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


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:
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'
  $results = $this->Film_model->search($limit, $offset, $sort_by, $sort_order);
  $data['films'] = $results['rows'];
  $data['num_results'] = $results['num_rows'];
  // 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;
  $data['pagination'] = $this->pagination->create_links();
  $data['sort_by'] = $sort_by;
  $data['sort_order'] = $sort_order;

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


In model:
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')
   ->limit($limit, $offset)
   ->order_by($sort_by, $sort_order);
  $ret['rows'] = $q->get()->result();
  // count query
  $q = $this->db->select('COUNT(*) as count', FALSE)
  $tmp = $q->get()->result();
  $ret['num_rows'] = $tmp[0]->count;
  return $ret;


Can you solve this problem?

Thank you

Best wishes,

[eluser]Abdul Malik Ikhsan[/eluser]
add function __construct to controller :
class Films extends CI_Controller
   public function __construct()
   //other functions...

I tried to add function __construct to controller but not working and same error message.
Any idea?

[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 ?

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?

Model Line "class Film_model extends CI_Controller"
Should extend CI_Model "class Film_model extends CI_Model"

Silly me. Thanks. it is really working Smile

Theme © iAndrew 2016 - Forum software by © MyBB