Welcome Guest, Not a member yet? Register   Sign In
Loading Models, order
#1

[eluser]nthvision[/eluser]
PHP throws me an "undefined property" error if I do the following....

Code:
function __construct()
{

parent::__construct();

$this->load->library('pagination');
$this->load->model('admin_testimonials_model');

/*to HERE -->>*/
$this->load->model('admin_model');

/*MOVE FROM below HERE*/
$this->load->model('admin_testimonials_config_model');


if(!$this->admin_model->validate_session())
  {
   die('you do not have permission');
  }
else {
  
  //load required models

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

can anyone help?
#2

[eluser]coolfactor[/eluser]
We need a bit more information in order to know where the problem is. I don't see anything wrong with that code. Can you post more and/or the exact error message?
#3

[eluser]nthvision[/eluser]
[quote author="coolfactor" date="1357372825"]We need a bit more information in order to know where the problem is. I don't see anything wrong with that code. Can you post more and/or the exact error message?[/quote]

sure, here it is.
...this post relates back to the other one you replied to.. its the same code, but I found two different bugs... the order in which I load the models effects which ones CI lets me use, as for the other ones I have to use the $CI super object to get it to work.



Code:
<?php
class Testimonials extends CI_Controller
{

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

//load libraries
$this->load->library('pagination');
//load required models
$this->load->model('admin/admin_model');
$this->load->model('admin/testimonials_model');
$this->load->model('admin/testimonials_config_model');


if(!$this->admin_model->validate_session())
  {
   die('you do not have permission');
  }
else {
  


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



}

/*=============*/
// 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_config_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_config_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{
/*============================*/
/*LINE 145 HACK FOR ERROR HERE*/
$CI =& get_instance();
/*============================*/

//NOTICE the i call $CI->testimonials_model.. instead of $this->testimonials_mode..
$this->data['testimonials'] = $CI->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

}




Theme © iAndrew 2016 - Forum software by © MyBB