I have created MY_Controller.php in the core folder. I autoloaded all the libraries and model that i want in my website. And also put some data in the MY_Controller.php. but when I extend this controller by another controller the data cannot be extended in the second controller. This is MY_Controller.php code.
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller
{
public $data;
public function __contstruct()
{
parent::__construct();
date_default_timezone_set('Asia/Karachi');
$this->load->library(array('ion_auth', 'form_validation','form'));
/*-Website Developer Information-*/
$this->data['FullName']="Waqas Dev lover";
$this->data['ShortName']="Dev Lover";
$this->data['Mobile']="03049211134";
$this->data['Version']="1.0.1";
$this->data['Copyright']="Waqas Dev Lover";
$this->data['Year']=date("Y");
$this->data['DevelopedBy']="Waqas Dev Lover";
$this->data['DevelopedByUrl']="http://www.facebook.com/xndltwaqas1";
/* -End of Website Developer Information- */
/*System Information */
$this->data["SectionH1"]="Admin panel";
/*End of System Information */
/*User Information */
$user_id =$this->session->userdata('user_id');
//echo =$this->ion_auth->logged_in();
//exit;
$this->data['user'] = $this->ion_auth->user($user_id)->row();
//$this->get_user_groups($user_id);
$this->data['group']=$this->ion_auth_model->get_users_groups($user_id)->result();
//var_dump($this->data['group']);
//exit();
/*End User Information */
}
public function show($path,$data=NULL){
if($data === NULL){
$data = $this->data;
var_dump($data); exit;
}
$this->load->view("template/header",$data);
$this->load->view("template/sidebar",$data);
$this->load->view($path,$data);
$this->load->view("template/footer",$data);
}
}
?>
And this is the Dashboard.php in which I want to extends the MY_Controller.php. But it Won't extends the Data in the Dashboard.php.
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends MY_Controller{
public function index(){
$this->show("admin/home");
}
}
__contstruct()in your MY_Controller class - if this isn't a typo you should alter it to__construct().