Php 在codeigniter中将变量从控制器传递给构造函数
如何将变量从控制器传递到构造函数Php 在codeigniter中将变量从控制器传递给构造函数,php,codeigniter-2,Php,Codeigniter 2,如何将变量从控制器传递到构造函数 function __construct() { parent::__construct(); $info['title'] = 'No title'; $this->load->view('include/header',$info); } function be_cool() { $info['body'] = 'template/becool'; $info['title'] = 'This
function __construct()
{
parent::__construct();
$info['title'] = 'No title';
$this->load->view('include/header',$info);
}
function be_cool()
{
$info['body'] = 'template/becool';
$info['title'] = 'This is the be cool title';
$this->load->view('include/template',$info);
}
function be_hot()
{
$info['body'] = 'template/behot';
$info['title'] = 'This is the be hot title';
$this->load->view('include/template',$info);
}
我试图根据控制器中定义的值更改标题。但它似乎不起作用。知道我做错了什么吗?你有语法错误。在您的
be_cool()
方法中:
$$his->load->view('include/template',$info);
应该是
$this->load->view('include/template',$info);
在你的另一种方法中,
$his
应该是$this
。我修复了这些错误,但我似乎仍然无法将标题值传递给构造函数..哦。您正在将标题加载到include/template视图中,但我怀疑您希望将其加载到标题中。不要每次都加载header视图,请查看一些模板库。这将为您节省大量资金: