Welcome Guest, Not a member yet? Register   Sign In
CI4 cannot start session
#1
Sad 

I add a line in Base Controller and run session. 

PHP Code:
<?php namespace App\Controllers;

/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *     class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 *
 * @package CodeIgniter
 */

use CodeIgniter\Controller;
use 
CodeIgniter\HTTP\IncomingRequest;
use 
Config\Database;

class 
BaseController extends Controller
{

    
/**
     * An array of helpers to be loaded automatically upon
     * class instantiation. These helpers will be available
     * to all other controllers that extend BaseController.
     *
     * @var array
     */
    
protected $helpers = [];
    protected 
$data = array();
        protected 
$session;
    protected 
$request;
    protected 
$db;

    
/**
     * Constructor.
     */
    
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {
        
// Do Not Edit This Line
        
parent::initController($request$response$logger);

        
//--------------------------------------------------------------------
        // Preload any models, libraries, etc, here.
        //--------------------------------------------------------------------
        // E.g.:
        
$this->session = \Config\Services::session();
        
        
// Connect Database
        
$this->db Database::connect();
        
        
// Request Income Data
        
$this->request service('request');        
    }




When I run my page, it show this massage :


Quote:Fatal error: Uncaught ErrorException: Cannot modify header information - headers already sent by (output started at C:\Users\hoffm\Dropbox\anaso\app\Config\Events.php:27) in C:\Users\hoffm\Dropbox\anaso\system\Debug\Exceptions.php:162 Stack trace: #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'Cannot modify h...', 'C:\\Users\\hoffm\\...', 162, Array) #1 C:\Users\hoffm\Dropbox\anaso\system\Debug\Exceptions.php(162): header('HTTP/1.1 500 In...', true, 500) #2 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException)) #3 {main} thrown in C:\Users\hoffm\Dropbox\anaso\system\Debug\Exceptions.php on line 162

Fatal error: Uncaught ErrorException: Cannot modify header information - headers already sent by (output started at C:\Users\hoffm\Dropbox\anaso\app\Config\Events.php:27) in C:\Users\hoffm\Dropbox\anaso\system\Debug\Exceptions.php:162 Stack trace: #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'Cannot modify h...', 'C:\\Users\\hoffm\\...', 162, Array) #1 C:\Users\hoffm\Dropbox\anaso\system\Debug\Exceptions.php(162): header('HTTP/1.1 500 In...', true, 500) #2 C:\Users\hoffm\Dropbox\anaso\system\Debug\Exceptions.php(223): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException)) #3 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler() #4 {main} thrown in C:\Users\hoffm\Dropbox\anaso\system\Debug\Exceptions.php on line 162


Do you have any suggestion for me ? please ~
Reply
#2

It's telling you that you have already sent something to the screen.

Check your code for output to the screen.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(05-13-2020, 03:17 AM)InsiteFX Wrote: It's telling you that you have already sent something to the screen.

Check your code for output to the screen.

Thank you for your reply.
I tried to download a new CI4, and start session in Base Controller directly.
But the result is same the problem too. 

So, I think it is my code problem.
Reply
#4

(This post was last modified: 05-14-2020, 04:11 AM by InsiteFX.)

Just look in your code where you are out putting to the view.

Also make sure you are not using the BOM and there are no spaces after the php tag.

And no ending php tag.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB