Friday, 29 July 2016

php - CodeIgniter Cannot modify header information



Hi Currently Im still Learning CodeIgniter. Im trying to use its session and enabled the session in autoload file



First the file structure of files is like this/



I structure my files like this. all templates will go in views/index.php



my problem is I get this error Cannot modify header information




I have a controller Home




class Home extends CI_Controller{

public function index()
{
$view['title'] = 'Welcome';


$data['data'] = $view;
$data['content'] = 'home';
$this->load->view('index',$data);
}

}


My views is something like this




views/index.php



 

//echo ("Welcome User: " . $datas["user_id"]);
$this->load->view('header',$data);
$this->load->view('template/' . $content);
$this->load->view('footer',$data);
?>




views/header.php



 






<?=$title?>






views/footer.php




   





then my content



views/template/home.php






Welcome







I don't know why do i get that error session. Please hope you could help me.
I didn't even set a session. I have just added it in auto load and don't know why i get that header problem. Is my file structure wrong?





A PHP Error was encountered



Severity: Warning



Message: Cannot modify header information - headers already sent by
(output started at site/application/controllers/home.php:2)



Filename: libraries/Session.php




Line Number: 675



Answer



You probably have a space before the opening tag in your Home controller which is causing output.



// a space here is enough to cause output

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...