在使用 Sentry 捆绑包时,我创建了LoginController
控制器来检查用户是否登录到他们被重定向的位置,以防万一。我的目的是将我所有的受限页面扩展到这个类,以使我的代码更高效。但为什么它不起作用?
登录控制器:
// Extends the BaseController
class LoginController extends BaseController {
public function __construct() {
if(!Sentry::check()) return Redirect::to('login');
}
}
我的实际控制人:
class MainController extends LoginController {
public function getIndex() {
if(Sentry::getUser()->hasAccess('view dashboard')) {
return View::make('admin.index');
} else {
return 'You have no access!';
}
}
}
我总是得到的错误:
Call to a member function hasAccess() on a non-object
什么有效:如果我if(!Sentry::check()) return Redirect::to('login');
直接添加 ingetIndex()
而不是__construct
,则重定向工作正常。为什么?