title: How to define FlashHelper/Component element for general authError message
body: <p>After updating CakePHP from 2.6.2 to 2.7.2 I get an missing key error when the auth flash message is created. How can I define the element template for the default <code>authError</code>?</p>
  
  <p>Since <code>SessionComponent::setFlash()</code> has been <a href="http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#displaying-notifications-or-flash-messages" rel="nofollow">deprecated</a> I added the <a href="http://book.cakephp.org/2.0/en/core-libraries/components/flash.html" rel="nofollow">FlashComponent</a> in <code>app/Controller/AppController.php</code> and modified all Flash messages from this:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>// Controller
  $this-&gt;Session-&gt;setFlash('Done', 'succeed');
  $this-&gt;Session-&gt;setFlash('There is an error', 'failure');
  $this-&gt;Session-&gt;setFlash('Please log in', 'auth');
  // View (default Layout)
  echo $this-&gt;Session-&gt;flash();
  echo $this-&gt;Session-&gt;flash('auth');
  </code></pre>
  
  <p>to this:</p>
  
  <pre class="lang-php prettyprint-override"><code>// Controller
  $this-&gt;Flash-&gt;succeed('Done');
  $this-&gt;Flash-&gt;failure('There is an error');
  $this-&gt;Flash-&gt;auth('Please log in');
  // View (default Layout)
  echo $this-&gt;Flash-&gt;render();
  echo $this-&gt;Session-&gt;flash();       // keep temporarily?
  echo $this-&gt;Session-&gt;flash('auth'); // keep temporarily?
  </code></pre>
  
  <p>I also copied the flash related templates from
  <code>App/View/Elements/succeed.ctp</code> to
  <code>App/View/Elements/Flash/succeed.ctp</code></p>
  
  <p>This is working – <strong>but</strong> if I am <strong>not logged in</strong> and try to access an admin page I get the default <a href="http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#AuthComponent::$authError" rel="nofollow">authError</a> message defined in <code>app/Controller/AppController.php</code> shown <strong>without</strong> the according template. With debug mode 2 I get the following error:</p>
  
  <pre class="lang-php prettyprint-override"><code>// 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"&gt;
  </code></pre>
  
  <p>What changes in AppController.php are necessary to get the default authError rendered with my own element template "auth"?</p>
  
  <p>Here the part of the AppController.php:</p>
  
  <pre class="lang-php prettyprint-override"><code>public $components = array(
    'Flash',
    'Session',
    'Security',
    'Auth' =&gt; array(
      'authenticate' =&gt; array('Form' =&gt; array('passwordHasher' =&gt; 'Blowfish')),
      'authError' =&gt; 'My default auth error message.', // How do I have to modify this line?
      'loginAction' =&gt; array('controller' =&gt; 'users', 'action' =&gt; 'login'),
      'loginRedirect' =&gt; array('controller' =&gt; 'users', 'action' =&gt; 'welcome'),
      'logoutRedirect' =&gt; array('controller' =&gt; 'users', 'action' =&gt; 'goodbye'),
    )
  );
  </code></pre>
  
  <p>And are these two lines still necessary when changing all flash messages in all Controllers to the Flash compoment and helper? Where else are they used by CakePHP?</p>
  
  <pre class="lang-php prettyprint-override"><code>echo $this-&gt;Session-&gt;flash();
  echo $this-&gt;Session-&gt;flash('auth');
  </code></pre>
  
  <p>I also had a look at the <a href="http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html" rel="nofollow">Authentication tutorial</a>. But it seems to be not up to date since <code>$this-&gt;Session-&gt;setFlash()</code> is still heavily in use...</p>