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?

553

Answer

Solution:

In the code provided, you havepublic function _construct() , but it should bepublic function __construct(). You need to add the double underscore__

335

Answer

Solution:

Load your helper using an array:

$this->load->helper( array('url') );

People are also looking for solutions to the problem: Duplication - php code duplicates row in MySQL - What is wrong?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.