CodeIgniter Forums

Full Version: Model Loading Bug ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]nthvision[/eluser]
Hi there!
I have an application where there is an Admin back end.. it works! however I noticed that when I swap the two lines after
Code:
parent::__construct();
that load my models my application breaks...
When I load my models like so...
Code:
//load models
$this->load->model('admin/admin_model');

$this->load->model('admin/master_testimonials_model','testimonials_model');

I get this php error...
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Testimonials::$testimonials_model

Filename: admin/testimonials.php

Line Number: 33

But when I swap them back to this..

Code:
//load models
$this->load->model('admin/master_testimonials_model','testimonials_model');

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

I get no php errors and it works just fine..

Any thoughts on this? I saw a post addressing the same issue I have on stack overflow, but no one really answered the question after the author noticed that just by swapping the lines the problem was fixed. I would REALLY like to know what is happening here. Thank you! Smile

Below is the code for the controller as well for the two models that I load in... I hope it helps.. I spent two days trying to figure this out.

Code:
<?php
class Testimonials extends CI_Controller
{

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

//load models
$this->load->model('admin/master_testimonials_model','testimonials_model');

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


//validate admin
if(!$this->admin_model->validate_session())
  {
   echo 'You don\'t have permission to access this page.';
   die();
  }

//load libraries
$this->load->library('pagination');


//initialize variables
$this->data['change_settings'] = FALSE;
$this->data['atleast_one_required_field'] = TRUE;
$this->data['testimonials_p_p_error'] = FALSE;

//THE LINE BELOW WOULD CORRESPOND TO LINE 34 FROM THE PHP ERROR
$this->data['num_of_new_testimonials'] = $this->testimonials_model->get_num_of_new_testimonials();

//load custom helper
$this->load->helper('admin');

}

/*=============*/
// index
/*=============*/
public function index()
{

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

/*================*/
// change_settings
/*================*/
public function change_settings()
{

$testimonial_required_fields_setting = 0;
$testimonial_required_fields_setting = $this->input->post('tc_require_phone') === 'true' ? $testimonial_required_fields_setting+1 : $testimonial_required_fields_setting;
$testimonial_required_fields_setting = $this->input->post('tc_require_email') === 'true' ? $testimonial_required_fields_setting+1 : $testimonial_required_fields_setting;
$testimonial_required_fields_setting = $this->input->post('tc_require_website') === 'true' ? $testimonial_required_fields_setting+1 : $testimonial_required_fields_setting;

if($testimonial_required_fields_setting > 0)
  {
   $this->testimonials_model->update_required_fields();
   $this->data['atleast_one_required_field'] = TRUE;
   $this->data['change_settings'] = TRUE; }
  else {
    $this->data['atleast_one_required_field'] = FALSE;
    $this->data['change_settings'] = FALSE; }
    
//check testimonials per page setting  
if( ($this->input->post('tc_testimonials_per_page') > 15) || ($this->input->post('tc_testimonials_per_page') <= 4))
{
$this->data['testimonials_p_p_error'] = TRUE;
}else{
$this->testimonials_model->set_config_value_plain('displayed_per_page',$this->input->post('tc_testimonials_per_page'));
}
$this->index();
}

/*==========*/
// approve
/*==========*/
public function approve($option = null, $id = null) {

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

if(strcasecmp($option, 'yes')==0)
{
  $approve = array('testimonial_approved'=>1);
  $this->db->where('id',$id);
  $this->db->update('nv_cms_testimonials',$approve);
  $this->data['approved']=true;
}
elseif(strcasecmp($option, 'no') == 0)
{
  $this->db->delete('nv_cms_testimonials',array('id'=>$id));
  $this->data['deleted']=true;
  
}
$this->data['new_testimonials'] = $this->testimonials_model->get_new_testimonials();
$this->load->view('admin/testimonials_approve_view.php',$this->data);
}

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


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


$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'] = $this->testimonials_model->get_all_testimonials_with_pagination('5',$this->uri->segment(4));

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

$this->data['pagination_links'] = $this->pagination->create_links();
$this->load->view('admin/testimonials_manage_view',$this->data);

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


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

}else{


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

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

$this->data['pagination_links'] = $this->pagination->create_links();
$this->load->view('admin/testimonials_manage_view',$this->data);
}

}//manage

}

El Forum

[eluser]nthvision[/eluser]
The code for the models is beyond the character limit so here is the paste bin link

Master_testimonials_model

Admin_model

El Forum

[eluser]Aken[/eluser]
Your admin model is extending CI_Controller which is incorrect.

El Forum

[eluser]nthvision[/eluser]
[quote author="Aken" date="1357682584"]Your admin model is extending CI_Controller which is incorrect.[/quote]

WOW THANK YOU, I can't believe I overlooked that! I was pulling my hair out!