php - CodeIgniter load lang-file in extended controller -


i have extended ci_controller this:

// base extend class my_controller extends ci_controller {       public $ci = array();        public function __construct() {         parent::__construct();         $this->ci = & get_instance();       }       public function isuser(){       // example       } }  // admin extended class my_admincontroller extends my_controller {       public $admin = array();       public function __construct() {          parent::__construct();          $this->ci->lang->load('admin');          $this->admin['lang'] = $this->ci->lang->line('admin');          $this->ci->load->vars($this->admin);       }        public function isadmin(){      //for example      } }  // extends modules class my_adminmodulecontroller extends my_admincontroller {      public function __construct() {         parent::__construct();         $this->ci->load->view('_header');      }      public function isallowedmodule(){      // example      }      public function pseudodestruct(){         $this->ci->load->view('_footer');      } } 

so works fine. try hook post_controllerevent , add my_adminmodulecontroller->pseudodestruct(), enabled hooks in config.php , added next lines hooks:

$hook['post_controller'] = array(     'class' => 'my_adminmodulecontroller',     'function' => 'pseudodestruct',     'filename' => 'my_controller.php',     'filepath' => 'core' ); 

but got problem @ loading lang-file in my_admincontroller's constructor. returns null when called hook (true when use normaly) , have notice undefined index @ frontend. no, don't want disable notices, want fix problem. have config loadings in my_admincontroller's constructor , them loading good.

you can't that, not in particular way @ least. codeigniter designed have 1 controller instance, while hooks create new instances , lang files not loaded in new instance. also, don't need call get_instance() controller class - class get_instance() returns.

anyway, can declare regular function use hook, there's no problem putting in my_controller.php file well:

function pseudo_destruct() {     get_instance()->load->view('_footer'); } 

then use hook:

$hook['post_controller'] = array(     'function' => 'pseudo_destruct',     'filename' => 'my_controller.php',     'filepath' => 'core' ); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -