我已经在MY_Controller.php
中创建了core folder
。我将我想要的所有libraries
和model
自动加载到了website
中。并将一些数据放入MY_Controller.php
中。但是当我通过另一个控制器扩展此控制器时,数据无法在第二个控制器中扩展。这是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
的{{1}}。但这不会扩展MY_Controller.php
中的数据。
Dashboard.php
答案 0 :(得分:1)
您已经可以add
append
,reset
或$this->data
MY_Controller
,而无需将额外的data
数组传递给{{ 1}}。
show
,并且可以在您的仪表板中直接使用它:
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");
}
}