【发布时间】:2012-06-12 14:01:30
【问题描述】:
在 Ci 上,您可以直接从控制器的构造函数加载视图,我正在加载页面的页眉和页脚(因为每个函数都相同)
class Add extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->view('header_view');
$this->load->view('footer_view');
}
function whatever()
{
//do stuff
}
}
但这会在加载我的函数之前加载页脚视图,所以有没有办法在每个函数结束时“手动”加载视图?
【问题讨论】:
-
您可以使用hooks 在控制器函数(post_controller_constructor)之前加载页眉,然后在之后加载页脚(post_controller)。
-
@Rocket 他不能也使用
__destruct()方法吗?还是我对此有错误的概念? -
使用 hooks 是一种创造性的方法,但如果您 100% 都不想使用页眉/页脚,它可能会变得很麻烦。
标签: php codeigniter