php - Helper not loading in Codeigniter?
432
Here is my simple controller:
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');
When I include $this->load->helper('url'); in view() the code works, but when I include it in the constructor as above then it doesn't. It also works if I autoload url helper.
Any ideas?
Answer
Solution:
In the code provided, you have
public function _construct()
, but it should bepublic function __construct()
. You need to add the double underscore__
Answer
Solution:
Load your helper using an array: