Welcome Guest, Not a member yet? Register   Sign In
Model is loaded but I get error.
#1

[eluser]nthvision[/eluser]
PHP keeps throwing me this error
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Testimonials::$testimonials_model

Filename: admin/testimonials.php

Line Number: 138

Even though I clearly loaded my model within the constructor...

Code:
<?php
class Testimonials extends CI_Controller
{

public $data = array();
/*============*/
// constructor
/*============*/
function __construct()
{
parent::__construct();

$this->load->model('admin/admin_model');


if(!$this->admin_model->validate_session())
  {
   die('you do not have permission');
  }
else {
  
  //load required models
  $this->load->model('admin/testimonials_config_model');
  $this->load->model('admin/testimonials_model');
  //initialize variables
  $this->data['change_settings'] = FALSE;
  $this->data['atleast_one_required_field'] = TRUE;
  $this->data['testimonials_p_p_error'] = FALSE;
}



}



/*=========*/
// manage
/*=========*/
public function manage($action = null, $id = null) {




$this->data['deleted'] = false;

if(strcasecmp($action, 'delete') == 0 )
{
$this->db->delete('nv_cms_testimonials',array('id'=>$id));
$this->data['deleted']=true;

$this->data['testimonials'] = $CI->testimonials_model->get_all_testimonials();
$this->load->view('admin/testimonials_manage_view',$this->data);

}
elseif(strcasecmp($action, 'edit')==0)
{


$this->data['testimonial'] = $CI->testimonials_model->get_testimonial_by_id($id);
$this->load->view('admin/testimonials_edit_view',$this->data);
}
elseif(strcasecmp($action, 'update')==0)
{
$CI->testimonials_model->update_testimonial($id);

}else{




$this->data['testimonials'] = $this->testimonials_model->get_all_testimonials_with_pagination('5',$this->uri->segment(4));

//pagination
$this->load->library('pagination');
$config['base_url'] = base_url().'admin/testimonials/manage';
$config['total_rows'] = $CI->testimonials_model->get_all_testimonials;
$config['per_page'] = 5;
$this->pagination->initialize($config);


$this->load->view('admin/testimonials_manage_view',$this->data);
}

}//manage

}

Any thoughts on this?
#2

[eluser]coolfactor[/eluser]
It looks like you're using $CI instead of $this to access your model.
#3

[eluser]nthvision[/eluser]
[quote author="coolfactor" date="1357372681"]It looks like you're using $CI instead of $this to access your model.[/quote]

I had to use the $CI super object to "hack" my way through and enable use of the said model and its methods :/
#4

[eluser]PhilTem[/eluser]
I don't see why you would need to use $CI if $this must work as well. Secondly, you do not define $CI anywhere, so you are accessing something that's not there.




Theme © iAndrew 2016 - Forum software by © MyBB