CakePHP を 2.6.2 から 2.7.2 に更新した後、認証フラッシュ メッセージが作成されるときにキーが見つからないというエラーが表示されます。デフォルトの要素テンプレートを定義するにはどうすればよいですauthError
か?
SessionComponent::setFlash()
は廃止されたため、 FlashComponentを追加し、app/Controller/AppController.php
すべての Flash メッセージを次のように変更しました。
// Controller
$this->Session->setFlash('Done', 'succeed');
$this->Session->setFlash('There is an error', 'failure');
$this->Session->setFlash('Please log in', 'auth');
// View (default Layout)
echo $this->Session->flash();
echo $this->Session->flash('auth');
これに:
// Controller
$this->Flash->succeed('Done');
$this->Flash->failure('There is an error');
$this->Flash->auth('Please log in');
// View (default Layout)
echo $this->Flash->render();
echo $this->Session->flash(); // keep temporarily?
echo $this->Session->flash('auth'); // keep temporarily?
また、フラッシュ関連のテンプレートを から
App/View/Elements/succeed.ctp
に
コピーしましたApp/View/Elements/Flash/succeed.ctp
これは機能していますが、ログインせずに管理ページにアクセスしようとすると、テンプレートが表示されていないデフォルトのauthErrorメッセージが表示されます。デバッグ モード 2 では、次のエラーが発生します。app/Controller/AppController.php
// Undefined variable: key [CORE\Cake\View\Elements\Flash\default.ctp, line 1]
// include - CORE\Cake\View\Elements\Flash\default.ctp, line 1
// View::_evaluate() - CORE\Cake\View\View.php, line 971
// View::_render() - CORE\Cake\View\View.php, line 933
// View::_renderElement() - CORE\Cake\View\View.php, line 1227
// View::element() - CORE\Cake\View\View.php, line 418
// SessionHelper::flash() - CORE\Cake\View\Helper\SessionHelper.php, line 159
// include - APP\View\Layouts\default.ctp, line 142
// View::_evaluate() - CORE\Cake\View\View.php, line 971
// View::_render() - CORE\Cake\View\View.php, line 933
// View::renderLayout() - CORE\Cake\View\View.php, line 546
// View::render() - CORE\Cake\View\View.php, line 481
// Controller::render() - CORE\Cake\Controller\Controller.php, line 960
// Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 200
// Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 167
// [main] - APP\webroot\index.php, line 118
// Message" class="message">
独自の要素テンプレート「auth」でレンダリングされるデフォルトの authError を取得するには、AppController.php でどのような変更が必要ですか?
AppController.php の一部:
public $components = array(
'Flash',
'Session',
'Security',
'Auth' => array(
'authenticate' => array('Form' => array('passwordHasher' => 'Blowfish')),
'authError' => 'My default auth error message.', // How do I have to modify this line?
'loginAction' => array('controller' => 'users', 'action' => 'login'),
'loginRedirect' => array('controller' => 'users', 'action' => 'welcome'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'goodbye'),
)
);
また、すべてのコントローラーのすべてのフラッシュ メッセージをフラッシュ コンポーネントとヘルパーに変更する場合、これらの 2 行はまだ必要ですか? それらは CakePHP によって他にどこで使用されますか?
echo $this->Session->flash();
echo $this->Session->flash('auth');
Authentication tutorialも見ました。$this->Session->setFlash()
しかし、まだ頻繁に使用されているため、最新ではないようです...