Auth コンポーネントを使用しています。現在、ログインしていないユーザーが「管理者」ページ (adminhome.ctp) にアクセスできないようにすることができます。しかし、isAuthorized()
管理者以外がページにアクセスできないようにする方法がわかりません。
AppController の内部:
public function beforeFilter() {
$this->Auth->allow('index', 'view', 'login', 'logout', 'display');
$this->Auth->authorize = array('Controller');
//$this->Auth->autoRedirect = false;
}
public function isAuthorized($user_id) {
$this->loadModel('User');
$user = $this->User->findById($this->Auth->user());
if ( $user['User']['role'] === 'admin') {
$this->Session->setFlash('isAuthorized');
return true;
}
$this->Session->setFlash('!isAuthorized');
return false;
}
PagesController の beforeFilter() は次のとおりです。
function beforeFilter() {
$this->Auth->deny('adminhome');
}
私たちは何を間違っていますか?