这是我的简单控制器:
public function _construct()
{
parent::_construct();
$this->load->helper('url');
}
public function view($page = "index")
{
if ( ! file_exists(APPPATH.'/views/truelove_view/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$this->load->view('truelove_view/templates/header.php');
$this->load->view('truelove_view/'.$page);
$this->load->view('truelove_view/templates/footer.php');
当我包含$this->load->helper('url')时;在view()中,代码是有效的,但当我如上所述将其包含在构造函数中时,它就不起作用了。如果我自动加载url助手,它也可以工作。
有什么想法吗?
在提供的代码中,您有public function _construct()
,但它应该是public function __construct()
。您需要添加双下划线__
使用数组加载助手:
$this->load->helper( array('url') );