助手没有加载到 Codeigniter 中?
Helper not loading in Codeigniter?
这是我的简单控制器:
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') );
这是我的简单控制器:
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') );