在我的BaseController
(默认的那个中有setupLayout函数)我有一个检查身份验证的构造...因为每个页面都必须登录才能使用它:
function __Construct(ISomethingRepository $somethingRepo)
{
$this->somethingRepository = $somethingRepo;
$result = Request::path();
if( $result != "not-authenticated" )
{
$this->CheckIfSomethingAuthenticationRequiresRedirection();
}
}
然后在我的BaseController中我有一个函数:
protected function CheckIfSomethingAuthenticationRequiresRedirection()
{
if( !$this->somethingRepository->IsAuthenticated() )
{
return Redirect::action( 'AuthenticationController@NotAuthenticated' );
}
// Otherwise finish off with the normal controller stuff
}
当它到达Redirect :: action时...它永远不会到达那个控制器方法......它只是做了一些废话...然后最终继续使用原始Controller(因此认证被破坏)。< / p>
任何想法在这里出了什么问题?
答案 0 :(得分:1)
需要从公共控制器方法将Redirect :: action()返回给用户,以便进行重定向。你让它从受保护的方法返回到你的构造函数,但是你没有做任何事情来将重定向返回给用户的浏览器。
您可能必须使用PHP header()而不是Redirect :: action(),因为您可能无法从构造函数返回Redirect。