Welcome Guest, Not a member yet? Register   Sign In
Redirection in a helper
#3

OK, so I'm not calling a helper, I'm calling $this->redirectIfNotLoggedIn() inherited from the BaseController.

Here is my new code:
PHP Code:
// in BaseController:

protected function redirectIfNotLoggedIn()
{
    if ($session->get('loggedUser') === null)
    {
        $this->response->setHeader('Location'site_url('user/login'));
    }
}

// in a controller:

public function create()
{
    $this->redirectIfNotLoggedIn();
    // ...


But that doesn't work! The response is correctly modified, but the page still displays without the redirection. Any other idea on what I should do to redirect?

Site note:

https://codeigniter4.github.io/userguide...l#redirect states that redirect() takes a string parameter called URI. This might be an error in the doc.
Reply


Messages In This Thread
Redirection in a helper - by SteeveDroz - 10-12-2019, 11:50 PM
RE: Redirection in a helper - by Ekley - 10-13-2019, 03:13 AM
RE: Redirection in a helper - by SteeveDroz - 10-13-2019, 09:54 PM
RE: Redirection in a helper - by kilishan - 10-14-2019, 06:38 AM
RE: Redirection in a helper - by SteeveDroz - 10-14-2019, 10:28 PM
RE: Redirection in a helper - by ahmad_arief - 10-03-2020, 04:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB