0
今天我遇到了我的CakePHP 3应用程序的怪异行为。如果用户没有登录(在AuthController
中检测到),它应该重定向到登录页面并显示一条消息。相反,它会从XYController引发异常,导致缺少凭据。该控制器结构的意见,分解和简化:控制器中的奇怪继承
class AuthController extends AppController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth');
if (empty($this->Auth->getCredentials())) {
$this->Flash->error(__('You have to sign in to access the user area.'));
//THIS CODE IS REACHED! I'VE CHECKED
return $this->redirect(['language' => $this->language, 'controller' => 'Pages', 'action' => 'display', 'login'], 200, true);
}
}
class XYController extends AuthController
{
public function index() {
//THE CLOUD THROWS "AccessDeniedAcception" (as excepted)
//THE ERROR IS SHOWN IN THE BROWSER ON AN ERROR PAGE - WHY ?!?!
$data = getSomeDataFromCloud();
...
}
}
我完全不明白,为什么显示从云例外。我想,来自父控制器的initialize()
方法将首先运行并执行重定向,然后到达子控制器的index()
。我错过了什么?