Displaying Auth Error Messages

I feel a bit daft posting this because in the end the answer was so easy to find – but maybe it will help somebody else.

I’ve been re-writing my users / groups permission system for CakePHP 1.2 and decided to incorporate as much built in functionality as possible so I’m using the Auth Component – which is great – but one thing kept bugging me, I couldn’t for the life of me figure out how to get the messages from Auth to display in my views – but by debugging I could see they were sitting there right in the Session.

I spent a long time Googling and looking at the API for clues, eventually in desperation I looked at the cookbook (I have no idea why I hadn’t already looked there – as I use it a lot…) and the answer was both very easy and staring me right in the face.

Just pop the following in a view or layout:

if ($session->check('Message.auth')) {