Hey gang, I am trying to redirect from my BaseController with a function called by the child Controller but it doesn't seem to work. Here is what I have.
BaseController.php
PHP Code:
class BaseController extends Controller
{
/**
* @var \CodeIgniter\Session\Session|mixed|null
*/
protected $session;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
$this->session = \Config\Services::session();
}
public function check_something()
{
// redirect if something in session doesn't check out
if (empty($this->session->get('something'))) redirect()->to('/somewhere');
}
}
ChildController.php
PHP Code:
class ChildController extends BaseController
{
public function index(){
// check something first
$this->check_something();
// if we are not redirected...
echo 'everything checked out!';
}
}
To answer the question: Yes, the session variable 'something' has not been created and empty($this->session->get('something')) returns true;
Any help greatly appreciated. Thank you!