Question

I've came across something that drives me crazy. please help me :(

I'm try to extend the CI_Loader Core in-order to create global header and footer. For some reason, the extending causes error.

The extend code:

class MY_Loader extends CI_Loader
{
    function __construct()
    {
        // i need the codeigniter super-object 
        // in all the functions
        $CI =& get_instance();
    }

    public function load_header()
    {
        echo 'header';
    }

    public function load_footer()
    {
        echo 'footer';
    }

}

The error i currently get

Unable to load the requested file: helpers/url_helper.php

UPDATE: CHANGED THE CODE - NEW ERROR

class MY_Loader extends CI_Loader
{

    function __construct() {
        parent::__construct();

        $CI =& get_instance();
        $CI->load = $this;
    }

    public function load_header()
    {
        echo 'header';
    }

    public function load_footer()
    {
        echo 'footer';
    }

}

now i get some error with the header

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /mounted-storage/home75b/sub007/sc43190-SREL/gogetmilk.com/application/core/MY_Loader.php:1)

Filename: libraries/Session.php

Line Number: 672

UPDATE #2 I'm not its the right way to fix it. but its working.

line 672 in libraries/Session.php sets a cookie

i've added a test to see if headers were already sent:

    if (! headers_sent() )
    {
        setcookie(
            $this->sess_cookie_name,
            $cookie_data,
            $expire,
            $this->cookie_path,
            $this->cookie_domain,
            $this->cookie_secure
        );           
    }

its not working ok. i've created session before printing anything, after printing, within views, after loading views, etc..

does anyone believe this will cause any problems?

problem solved and was not related to codeigniter. see answer at the bottom.

Was it helpful?

Solution 3

Problem solved. it wasn't even a CodeIgniter Issue.

It was an invisble BOM at the begining of the file. Used this application to remove this bytes: http://sourceforge.net/projects/bomremover/

Thanks everybody for your help :)

OTHER TIPS

The error i currently get Unable to load the requested file:

helpers/url_helper.php

You're getting this error because you didn't load URL helper. I don't see any call to any URL helper function so I assume the error is being thrown in another file ... Try adding

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

in relevant file or just load it in the config/autoload.php

and, yes, use parent::__construct(); as answered by Broncha

Your construct should call the parent's construct

function __construct()
{
    parent::__construct();
    // i need the codeigniter super-object 
    // in all the functions

    $CI =& get_instance();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top