cakephp - How to define FlashHelper/Component element for general authError message -
after updating cakephp 2.6.2 2.7.2 missing key error when auth flash message created. how can define element template default autherror
?
since sessioncomponent::setflash()
has been deprecated added flashcomponent in app/controller/appcontroller.php
, modified flash messages this:
// controller $this->session->setflash('done', 'succeed'); $this->session->setflash('there error', 'failure'); $this->session->setflash('please log in', 'auth'); // view (default layout) echo $this->session->flash(); echo $this->session->flash('auth');
to this:
// controller $this->flash->succeed('done'); $this->flash->failure('there 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?
i copied flash related templates app/view/elements/succeed.ctp
app/view/elements/flash/succeed.ctp
this working – but if not logged in , try access admin page default autherror message defined in app/controller/appcontroller.php
shown without according template. debug mode 2 following error:
// 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">
what changes in appcontroller.php necessary default autherror rendered own element template "auth"?
here part of appcontroller.php:
public $components = array( 'flash', 'session', 'security', 'auth' => array( 'authenticate' => array('form' => array('passwordhasher' => 'blowfish')), 'autherror' => 'my default auth error message.', // how have modify line? 'loginaction' => array('controller' => 'users', 'action' => 'login'), 'loginredirect' => array('controller' => 'users', 'action' => 'welcome'), 'logoutredirect' => array('controller' => 'users', 'action' => 'goodbye'), ) );
and these 2 lines still necessary when changing flash messages in controllers flash compoment , helper? else used cakephp?
echo $this->session->flash(); echo $this->session->flash('auth');
i had @ authentication tutorial. seems not date since $this->session->setflash()
still heavily in use...
in auth component setting array add like
'auth' = [ ... 'flash' => ['element' => 'auth_error'], ... ]
then create template named auth_error.ctp
in element/flash
directory. in file variable use should $message
, because when cake calls flash auth components not pass other variable (i.e. $key
variable)
maybe answer not 100% correct (so suggestion welcome) worked me.
Comments
Post a Comment