Welcome Guest, Not a member yet? Register   Sign In
Call to a member function initialize()
#1

[eluser]Adnan1984[/eluser]
Hello,

I saw a video tutorial "CodeIgniter from Scratch: Displaying & Sorting Tabular Data" (http://net.tutsplus.com/tutorials/php/co...ular-data/)

It is really good working in CodeIgniter 1.7 version. And now i am using CodeIgniter 2.1 version or latest version. it is not working and i got error message. it says:


A PHP Error was encountered
Severity: Notice
Message: Undefined property: Films::$pagination
Filename: controllers/films.php
Line Number: 30

Fatal error: Call to a member function initialize() on a non-object in C:\XAMPP\HTDOCS\Ci_test_2_1\application\controllers\films.php on line 30

In Controller:
Code:
<?php
class Films extends CI_Controller {

function display($sort_by = 'title', $sort_order = 'asc', $offset = 0) {
  
  $limit = 20;
  $data['fields'] = array(
   'FID' => 'ID',
   'title' => 'Title',
   'category' => 'Category',
   'length' => 'Length',
   'rating' => 'Rating',
   'price' => 'Price'
  );
  
  $this->load->model('Film_model');
  
  $results = $this->Film_model->search($limit, $offset, $sort_by, $sort_order);
  
  $data['films'] = $results['rows'];
  $data['num_results'] = $results['num_rows'];
  
  // pagination
  $this->load->library('pagination');
  $config = array();
  $config['base_url'] = site_url("films/display/$sort_by/$sort_order");
  $config['total_rows'] = $data['num_results'];
  $config['per_page'] = $limit;
  $config['uri_segment'] = 5;
  $this->pagination->initialize($config);
  $data['pagination'] = $this->pagination->create_links();
  
  $data['sort_by'] = $sort_by;
  $data['sort_order'] = $sort_order;

  
  $this->load->view('films', $data);
}

}

In model:
Code:
<?php
class Film_model extends CI_Controller {

function search($limit, $offset, $sort_by, $sort_order) {
  
  $sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
  $sort_columns = array('FID', 'title', 'category', 'length', 'rating', 'price');
  $sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'title';
  
  // results query
  $q = $this->db->select('FID, title, category, length, rating, price')
   ->from('film_list')
   ->limit($limit, $offset)
   ->order_by($sort_by, $sort_order);
  
  $ret['rows'] = $q->get()->result();
  
  // count query
  $q = $this->db->select('COUNT(*) as count', FALSE)
   ->from('film_list');
  
  $tmp = $q->get()->result();
  
  $ret['num_rows'] = $tmp[0]->count;
  
  return $ret;
}


}

Can you solve this problem?

Thank you

Best wishes,
Adnan
#2

[eluser]Abdul Malik Ikhsan[/eluser]
add function __construct to controller :
Code:
class Films extends CI_Controller
{
   public function __construct()
   {
       parent::__construct();
   }
  
   //other functions...
}
#3

[eluser]Adnan1984[/eluser]
I tried to add function __construct to controller but not working and same error message.
Any idea?
#4

[eluser]Abdul Malik Ikhsan[/eluser]
i'm using CI 2.1.2, it works.
maybe, upgrade your CI or check your php environment.
what php version you use ?
#5

[eluser]Adnan1984[/eluser]
Mine is CI 2.1.2 and i am using XAMPP (PHP Version 5.3.5).
Did u try to run for my programming code which i sent the post?
#6

[eluser]qcsites[/eluser]
Model Line "class Film_model extends CI_Controller"
Should extend CI_Model "class Film_model extends CI_Model"
#7

[eluser]Adnan1984[/eluser]
Silly me. Thanks. it is really working Smile




Theme © iAndrew 2016 - Forum software by © MyBB