Avoid CakePHP's Auth component to display authentication error messages -


i rid of auth component error messages, specially autherror message comes whenever try access non-allowed action.

just sure, double check there no $this->session->flash() call anywhere in layout. besides, setting empty value not work, component has default message value.

i using auth component following configuration in appcontroller class:

class appcontroller extends controller {     var $components = array(         'auth' => array(             'usermodel' => 'webuser',             'loginaction' => '/login',             'loginredirect' => '/',             'logoutredirect' => '/login',             'autoredirect' => false,         ),         'session',         ...      ... } 

for login , logout redirections have setup 2 routes:

router::connect('/', array('controller' => 'posts', 'action' => 'index')); router::connect('/login', array('controller' => 'web_users', 'action' => 'login')); 

the login action within webuser controller empty; change default layout:

function login() {     $this->layout = 'login';     $this->set('title_for_layout', 'sign in'); } 

finally, have simple login.ctp layout file:

<html>     <head>         ...     </head>     <body>         ...         <?php echo $content_for_layout; ?>         ...     </body> </html> 

when access http://example.com/login there no problem, no messages, login form. default autherror message when requesting other action, after auth component redirects login action. 2 questions arise:

  1. why auth component displaying flash messages when there no $this->session->flash() call anywhere? (see update 2 below)
  2. how can setup empty/null value in autherror attribute?

thanks!

update

i came ugly solution: created element login_error.ctp , assigned flashelement attribute in auth component initialization:

class appcontroller extends controller {     var $components = array(         'auth' => array(             'flashelement' => 'login_error',         ...      ... } 

in login_error.ctp compare autherror default message:

<?php if ( $message !== 'you not authorized access location.' ): ?> <div id="flashmessage" class="message"><?php echo $message; ?></div> <?php endif; ?> 

it works, hate it!

update 2

thanks dogmatic69 answer forced myself check again. found call $this->session->flash() being made. on little view element had wrote before. had nothing login/logout stuff did not pay attention file.

update 3

thanks spawncxy answer well. copying auth component , making custom modifications better approach string comparison.

just remove $this->session->flash('auth') view/layout.

http://book.cakephp.org/view/1467/flash


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -