0

referring to the answer in this link

Load Controller Within Controller

as answered by Zain Abbas, I made a n approach

here's my common controller

<?php
class Common extends CI_Controller {
    public function __construct() {
        parent::__construct();

    }
    function page_list()
       {
         return $this->autoload_model->get_data_from_table("td_page","*","page_id > 0");
       }
    function banner_list()
       {
         return $this->autoload_model->get_data_from_table("td_banner","*","banner_id > 0
                                                                               ORDER BY banner_priority ASC");
       } 
}

?>

and here's my index controller

<?php
class index extends CI_Controller {
    public function __construct() {
        parent::__construct();
        @session_start();
    }
    function index()
    {
       $this->load->library('../controllers/common');
       $data['product_list']=$this->autoload_model->get_data_from_table("td_category,td_product","*",
                                                                       "td_category.category_id = td_product.category_id
                                                                        AND td_product.product_id > 0
                                                                        ORDER BY RAND(NOW()) LIMIT 20")->result_array();
       //$banner_list = $this->common->banner_list();

       $this->load->view('header',$data);
       $this->load->view('slider');
       $this->load->view('leftcategory');

       $this->load->view('homeproduct');
       $this->load->view('featured');
       $this->load->view('footer');
    }
}?>

and this one is my autoload model

<?php
class autoload_model extends CI_Model{
    function __construct() {
        parent::__construct();
   }

/*---------data fetching-----------*/
    function get_data_from_table($table,$data,$cond)
    {
        $this->db->select($data);
        $this->db->where($cond);
        $result= $this->db->get($table);
        return $result;
    }
   /*---------ends-----------*/
}
?>

i am getting a page list of error, i dont know, what wrong did i do.. They claimed it to be working

Community
  • 1
  • 1
Saswat
  • 12,320
  • 16
  • 77
  • 156

1 Answers1

0

I found it out guys. Using a controller as library may override the functionalities. SO it will be better if we just extend the controller

Saswat
  • 12,320
  • 16
  • 77
  • 156