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');
直接追加すると、リダイレクトは正常に機能します。なんで?getIndex()
__construct