Previously I was using Codeigniter 3 and I load all helpers, libraries using the autoload.php. Now migrating to CI4 where I tried the following,
- I tried loading my helper files in the
BaseController.php - I tried loading the helper in
__constructat myController.phpas well.
I have a Library say Demo.php and function check_user_logged(). When I called my get_cookie() from the function, it says Call to undefined function App\Libraries\get_cookie().
This function check_user_logged() when it is called from a controller as,
<?php
use App\Libraries\Demo;
protected $demo;
public function __construct()
{
helper('cookie');
$this->demo = new Demo();
}
public function index()
{
$this->demo->check_user_logged();
}
The Demo.php
<?php
namespace App\Libraries;
Class Demo
{
public function check_user_logged()
{
print_r(get_cookie('name')); // just for simplicity printing the cookie
}
}
Is it the only way to load the cookie helper in Demo library constructor? Or I am missing something?