Tweet I’m playing around a bit with CakePHP again today … and for some reason a few things REALLY did my head in. Like REALLY did my head in. Stupid really because about a year ago I built a full web solution in CakePHP with users, ACL, AUTH and all that stuff – and deployed [...]
I’m playing around a bit with CakePHP again today … and for some reason a few things REALLY did my head in. Like REALLY did my head in.
Stupid really because about a year ago I built a full web solution in CakePHP with users, ACL, AUTH and all that stuff – and deployed it. I guess that’s what you get however when you don’t develop full time. You loose things.
So, I started again – grabbing a copy of CakePHP and hitting the ground. Here’s a few things I found useful along the way:
- forget all about ACL, ACO and ARO’s – you don’t need them for user login/logout
- run through cakePHP‘s own auth tutorial (all you need is a User table in your database)
- the AUTH component will do all your heavy lifting (eg: password encryption etc) provided you have a USERNAME and PASSWORD – if however you instead use EMAIL and PASSWORD, it wont. And it won’t give you any decent errors. It’ll just do your head in!! However you can quickly and easily fix this – read how to quickly change the AUTH variables here – just tell AUTH that it’s username is actually your email address field.
- HTML helpers are fantastic, quickly rename a default form label using:
echo $form->input(‘database.feild_name’, array(‘label’=>’Use_this_name’));
I’ve also seen 101 different ways to output the data for the currently logged in user. From completely re-writing your Controllers and Models to … well all sorts of complicated ways. But I’m telling you there is a FAR simpler way to do it.
AUTH – it’s your friend, it really is!
Check if a user is logged in from your layout file:
- if( $session->check(‘Auth.User.id’) )
Write our a user name from your layout file:
Or if you are in your Controller simply use:
- $this->Auth->user(‘username’) // insert what ever database field you want
I knew there had to be simple ways to do this stuff!! Do you have any really simple, handy CakePHP tips you want to share?