Welcome Guest, Not a member yet? Register   Sign In
default data passed through BaseController

(This post was last modified: 03-29-2020, 06:07 AM by Codinglander.)

Hi there...

I'm trying to do my first project with CodeIgniter 4.

I want to pass standard data to View set inside the BaseController. 

But following code does not work:
Controller (BaseController)
PHP Code:
public $data = [
    'title' => 'defaultTitle',

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

   // Preload any models, libraries, etc, here.
   // E.g.:
   // $this->session = \Config\Services::session();

       $this->session = \Config\Services::session();

Users Controller:
PHP Code:
public function index()
        $this->data['title'] = 'my own title';
        echo view('users/profile',$this->data);

I want to have default variables which I can change in the controller.

Any Ideas ?


Now it works fine, but I get an error with preloading "session":

Quote:Fatal error: Uncaught ErrorException: touch(): Unable to create file NULL/ci_session7roacrtom0dsiftqc3pdd0j1jnjv6ejo because No such file or directory in C:\xampp\htdocs\kighlander.local\system\Session\Handlers\FileHandler.php:252 Stack trace: #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'touch(): Unable...', 'C:\\xampp\\htdocs...', 252, Array) #1 C:\xampp\htdocs\kighlander.local\system\Session\Handlers\FileHandler.php(252): touch('NULL/ci_session...') #2 [internal function]: CodeIgniter\Session\Handlers\FileHandler->write('7roacrtom0dsift...', '__ci_last_regen...') #3 [internal function]: session_write_close() #4 {main} thrown in C:\xampp\htdocs\kighlander.local\system\Session\Handlers\FileHandler.php on line 252

Messages In This Thread
default data passed through BaseController - by Codinglander - 03-29-2020, 05:44 AM

Theme © iAndrew 2016 - Forum software by © MyBB