Domanda

In my BaseController (The default one which has that setupLayout function in it) I have a construct that checks for authentication... Because every page must be logged in to use it:

function __Construct(ISomethingRepository $somethingRepo)
{
    $this->somethingRepository = $somethingRepo;
    $result = Request::path();
    if( $result != "not-authenticated" )
    {
        $this->CheckIfSomethingAuthenticationRequiresRedirection();
    }
}

and further down in my BaseController I have a function:

protected function CheckIfSomethingAuthenticationRequiresRedirection()
{
    if( !$this->somethingRepository->IsAuthenticated() )
    {
        return Redirect::action( 'AuthenticationController@NotAuthenticated' );
    }

    // Otherwise finish off with the normal controller stuff
}

When it gets to the Redirect::action... it never gets to that controllers method... It just does some crap... then ends up continuing with the original Controller (thus the authentication is broken).

Any ideas what's going wrong here?

È stato utile?

Soluzione

Redirect::action() needs to be returned to the user from a public controller method in order for the redirect to occur. You have it returning to your constructor from a protected method, but then you don't do anything to return the redirect to the user's browser.

You may have to use PHP header() instead of Redirect::action(), since you probably can't return the Redirect from a constructor.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top