好吧,您可以使用AuthComponentisAuthorized()中的函数。每个请求都会调用它。
public function isAuthorized($user){
return true; //allow the user to see the page
}
您可以debug($user)查看实际数据,如果您想从数据库中获取“新”信息,您始终可以像这样获取它们:
public function isAuthorized($user){
$current_user_from_database = $this->User->findById($user['id']);
if($current_user_from_database['User']['username'] != $user['username']){
$this->Session->setFlash('You\'ve changed the username. Please, login again.');
$this->redirect($this->Auth->logout);
return false;
}
return true;
}
查看API以获取更多信息和 PDF 书籍。您也可以观看有关 AuthComponent 的视频。这很棒。
如果您需要更多信息或帮助,请随时提出。
顺便提一句。如果您希望每次请求都调用函数,则必须在控制器中配置AuthComponent 。isAuthorized()