我已经在core folder
中创建了MY_Controller.php
。我在website
中自动加载了我想要的所有libraries
和model
。并将一些数据放入CCD_ 6中。但是当我用另一个控制器扩展这个控制器时,数据不能在第二个控制器中扩展。这是MY_Controller.php
代码。
<?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);
}
}
?>
这就是Dashboard.php
,我想在其中扩展MY_Controller.php
。但它不会扩展Dashboard.php
中的数据。
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends MY_Controller{
public function index(){
$this->show("admin/home");
}
}
您已经可以从MY_Controller
中获得add
、append
或reset
您的$this->data
,而无需向show
传递额外的data
数组。
public function show($path)
{
$this->load->view("template/header", $this->data);
$this->load->view("template/sidebar", $this->data);
$this->load->view($path, $this->data);
$this->load->view("template/footer", $this->data);
}
在您的仪表板中,您可以直接使用它:
class Dashboard extends MY_Controller
{
public function index()
{
$this->data['foo'] = 'bar';
$this->show("admin/home");
}
}
您现在可以在面板视图中访问$foo