Welcome Guest, Not a member yet? Register   Sign In
Autoloading Sessions caused multiple errors
#1

[eluser]spyro[/eluser]
I have a parent controller class that every controller inherits from. Before adding sessions it just called one header view to use for everyone.

Once I added sessions I gave it the capability to detect if a user was logged in and provide a different header view. See class below:

Code:
<?php

/* This class handles the loading of the header/footer for main pages.
   Sub-class me and over-ride page_content to create main page controllers. */
class MainPage extends Controller {

    function MainPage()
    {
        parent::Controller();
        $this->config->load('config');
    }
    
        // Handle loading header/footer and any other content that all main pages will have
    function index()
    {

        $data['base_url'] = $this->config->item('base_url');

        if ($this->session->userdata('logged_in') == TRUE)
        {
            $this->load->view('accountHeader_view',$data);
        }
        else
        {
            $this->load->view('mainHeader_view',$data);
        }
                
        $this->page_content();
        
        $this->load->view('mainFooter_view');
    }
        
    function page_content()
    {
            // Over-ride me in sub-class!
    }
}

?>

When a user is logged in I don't get any errors. When a user is not logged in I get the following:

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test\system\application\controllers\welcome.php:2)

Filename: libraries/Session.php

Line Number: 408

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test\system\application\controllers\welcome.php:2)

Filename: libraries/Session.php

Line Number: 662

Any idea on what is causing this?
#2

[eluser]Arjen[/eluser]
Did you solve your problem yet? I get a simular error message when auloloading session library. I checked on white spaces after the last closing tags but couldn't find any. Any suggestions? :question:
#3

[eluser]Arjen[/eluser]
I could fix the headers sent error with the next steps.

I replaced the files database/drivers/mysql/mysql_driver.php and
libraries/session.php with the files I downloaded from
http://dev.ellislab.com/svn/CodeIgniter/trunk/system/

That was enough to get rid of the error messages.
But I was still getting the same page twice, without any error message. After a search in my code lines there was a missing ';' in a model used bij DataMapper.
#4

[eluser]spyro[/eluser]
I did get it fixed but am not sure what was causing it in this instance. I was loading headers and footers via the controller but moved to a wrapper view layout instead so that I could also pass data to the header and footer. Somehow that fixed the errors. I am guessing that there was some kind of problem with the order that stuff was getting loaded but I am really not sure.




Theme © iAndrew 2016 - Forum software by © MyBB