i am doing this in all my Controllers for Menu But i want to do that i give it once in core folder of CI Any Suggestion ?

$data['cms_menus']=$this->database_model->GetRecords('cms_menus',false, array('FKMenuID'=>null));
foreach ($data['cms_menus'] as $key => $datas){
$data['cms_menus'][$key]['childs']=$this->database_model->GetRecords('cms_menus',false, array('FKMenuID'=> $datas['PKMenuID']));}

`

Hello,

in ./application/core/ create the file MY_Controller.php and extend it to CI_Controller and add a public (or protected) $data:

class MY_Controller extends CI_Controller {

    public $data;
    public function __construct()
    {
        parent::__construct();
        $this->data['menu'] = 'MENU DATA HERE';
    }
}

Then extend your controllers to MY_Controller instead of CI_Controller and when you want to send data to the views use $this->data instead of the canonical $data, for example:

class Blog extends MY_Controller {

    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->data['title'] = 'Blog Index';

        $this->load->view('common/header', $this->data);
        $this->load->view('blog/index', $this->data);
        $this->load->view('common/footer', $this->data);
    }
}

And it should work. Due to the nature of CI you don't have a lot of flexibility, if you are still starting consider other solutions like SlimPHP & co.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.