Codeigniter 覆盖CI_控制器
我已经覆盖了我的CI_控制器,因此我可以针对每个控制器执行特定的用户检查,例如,每个人都可以访问来宾_控制器,用户_控制器仅适用于登录的用户 这一切都很好,但我只覆盖了这里的输出Codeigniter 覆盖CI_控制器,codeigniter,Codeigniter,我已经覆盖了我的CI_控制器,因此我可以针对每个控制器执行特定的用户检查,例如,每个人都可以访问来宾_控制器,用户_控制器仅适用于登录的用户 这一切都很好,但我只覆盖了这里的输出 class Guest_Controller extends CI_Controller { public function __construct() { parent::__construct(); } public function _output($con
class Guest_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function _output($content)
{
// Load the base template with output content available as $content
$data['content'] = &$content;
echo($this->load->view('templates/html_guest', $data, true));
}
}
class Homepage extends Guest_Controller {
public function __contruct()
{
}
public function index()
{
$data = array(
'title' => 'Homagepage',
'page_title' => 'Homepage',
'body_classes' => 'home'
);
$this->parser->parse('homepage', $data);
}
}
在我的$data
中,你可以看到我有body_类
,我使用它,这样我可以根据每个页面的需要为每个页面提供一个单独的类。
现在,在我的Guest\u控制器
中添加默认的body\u类
的最佳方法是什么
如果body\u类
仅为home,如何向其添加一些默认类
编辑:所以我正在寻找一种方法来轻松地添加主体类,同时仍然有一些默认的主体类。这确实是一个选项,尽管我希望继续使用$this->parser->parse('homepage',$data);在我的Guest_控制器中有一些东西,也许你可以使用全局视图变量
class Guest_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function _output($content)
{
// Load the base template with output content available as $content
$data['content'] = &$content;
echo($this->load->view('templates/html_guest', $data, true));
}
//specify default values with $page_info
protected function get_page_info($page_info)
{
$data = array(
'title' => 'default',
'page_title' => 'default',
'body_classes' => 'default'
);
foreach ($page_info as $key => $value)
$data[$key] = $value;
return $data;
}
}
class Homepage extends Guest_Controller {
public function __contruct()
{
}
public function index()
{
$data = array(
'title' => 'Homagepage',
'page_title' => 'Homepage',
);
$this->parser->parse('homepage', $this->get_page_info($data));
}
}