Friday, December 13, 2013

Re: Customise authError message class

Why not just specify the element you need as the second parameter then create an element for each message type - then you have complete control over layout, styling, classes and eventhing.?


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 12 Dec 2013, at 22:59, seba <sebastian.allocca@gmail.com> wrote:

Solved. Here's the working solution for reference- 

Code snippet in /Controller/AppController.php: 

public function beforeFilter() { 
  //Set custom authError message if user tries to access a controller when not logged in 
  $this->Auth->authError = __('You are not authorized to view this page.'); 
  $this->Auth->flash['params']['class'] = 'alert alert-danger'; //Add this line to control output auth flash class
}

On Thursday, 12 December 2013 23:46:39 UTC+11, seba wrote:
I'm looking for advice on how to customize the authError message class (I'm using Twitter Bootstrap, so would like to use the alert styles from Bootstrap).

In /Controller/AppController.php I have the following snippet:

public function beforeFilter() {
  //Set custom authError message if user tries to access a controller when not logged in
  $this->Auth->authError = __('You are not authorized to view this page.');
}
Which produces this HTML (class="message":

<div id="authMessage" class="message"> You are not authorized to view this page.</div>

What I'd like to output is this HTML (class="alert alert-danger"):
<div id="authMessage" class="alert alert-danger"> You are not authorized to view this page.</div>

Much thanks in advance.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: