How to load view file in core functions in codeigniter

I'm trying to load a view file at application / core / MY_Controller.php, but its the following:

Message: Undefined property: Edustaticlanding::$load

Filename: core/MY_Controller.php

      

In MY_Controller.php, the function is executed as follows:

function menu(){
    $arrr = array();
    return $arrdata['menu'] = $this->load->view('menu',$arrr,true);
}

      

And I am calling this function in my controller (Edustaticlanding.php) like this.

function __construct(){
    $this->menucontent = $this->menu();
    print_r($this->menucontent); die;
}

      

Plc fix me .. where its wrong .. thanks

+3


source to share


3 answers


In app / core / MY _Controller.php

Add post $data = array()

as shown below

<?php

class MY_Controller extends CI_Controller 
{
    public $data = array();

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

        $this->data['menu'] = $this->menu();
    }

    public function menu(){
        return $this->load->view('menu', NULL, TRUE);
    }
}

      

On the controller after that add public $ data = array (); you can access the menu in the view



You should now use $this->data

on the controller

<?php

class Example extends MY_Controller {

    public $data = array();

    public function index() {

        $this->data['title'] = 'Welcome to Codeigniter';

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

    }
}   

      

In the example view, you can now echo

<?php echo $menu;?>

      

+2


source


Add extends CI_Controller

to your main controller for example the following codes:



class MY_Controller extends CI_Controller {

      

+2


source


Please check below mentioned solution. The parent constructor must be called first. This way it will load all the main configurations.

First class CI_Controller

class and calling parent constructor as described below

class MY_Controller extends CI_Controller {

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

}

      

Please let me if this doesn't work.

+2


source







All Articles