Welcome Guest, Not a member yet? Register   Sign In
Moving to ci4
#8

Yes the BaseController is where I setup my Sessions.

PHP Code:
<?php

namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
CodeIgniter\HTTP\CLIRequest;
use 
CodeIgniter\HTTP\IncomingRequest;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Config\Services;
use 
Psr\Log\LoggerInterface;

/**
 * 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.
 */
abstract class BaseController extends Controller
{
    /**
    * Instance of the main Request object.
    *
    * @var CLIRequest|IncomingRequest
    */
    protected $request;

    /**
    * 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 = [];

    /**
    * Be sure to declare properties for any property fetch you initialized.
    * The creation of dynamic property is deprecated in PHP 8.2.
    */
    protected $session;

    /**
    * Constructor.
    */
    public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request$response$logger);

        // Preload any models, libraries, etc, here.

        // E.g.: $this->session = \Config\Services::session();
        // Ensure that the session is started and running
        if (session_status() == PHP_SESSION_NONE) {
            $this->session Services::session();
        }

    }

    // -------------------------------------------------------------------

}  // End of Class BaseController.

/**
 * -----------------------------------------------------------------------
 * Filename: BaseController.php
 * Location: ./app/Controllers/BaseController.php
 * ----------------------------------------------------------------------- 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
Moving to ci4 - by richb201 - 06-17-2023, 07:50 AM
RE: Moving to ci4 - by iRedds - 06-17-2023, 08:03 AM
RE: Moving to ci4 - by richb201 - 06-17-2023, 09:10 AM
RE: Moving to ci4 - by iRedds - 06-17-2023, 11:01 AM
RE: Moving to ci4 - by kenjis - 06-17-2023, 02:10 PM
RE: Moving to ci4 - by InsiteFX - 06-17-2023, 11:02 PM
RE: Moving to ci4 - by richb201 - 06-20-2023, 03:20 PM
RE: Moving to ci4 - by InsiteFX - 06-20-2023, 11:02 PM
RE: Moving to ci4 - by richb201 - 06-21-2023, 04:45 AM
RE: Moving to ci4 - by kenjis - 06-21-2023, 04:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB