Gravatar for CakePHP
I’ve been playing around with CakePHP for a week or so and I think it has a lot of potential. The framework feels robust, complete and very handy once you get to know it. “As every thing else” I hear you saying, but the problem I’m having with CakePHP is the documentation.
Most of the times it’s incomplete or just assumes that you know way too much about the framework. Getting to work a simple authentication system using their built-in component has been quite a bit of a pain. And I’m not alone, the docs, the mailing list and many other blogs complain about the same. I’m thinking about writing yet another tuto myself, it’s really frustrating when you just want to get things done and you can’t…
I hope I’ve learnt from others so I’d make kick ass docs for HippoHX both for advanced developers AND newbies. Even though documenting sucks you/we must create good documentation.
Anyway. I’ve created a very simple Helper to handle Gravatars. Certainly not rocket science, but here it is:
-
/*
-
* Gravatar Helper.
-
* First import it. Either globally in your app_controller.php (app/app_controller.php) or in a specific controller:
-
* var $helpers = array(‘Gravatar’);
-
*
-
* Then just call it from your view like this:
-
* $gravatar->get(wadus@wadus.com);
-
*/
-
-
class GravatarHelper extends Helper {
-
-
-
function get($email,$size = 40){
-
return $this->output($this->Html->image("http://www.gravatar.com/avatar.php?gravatar_id=".md5($email)."&size=".$size));
-
}
-
-
}
So simple it doesn’t need documentation :P
November 20th, 2008 at 16:09
And of course just after posting I googled “gravatar cakephp” and found 200 helpers just like this one or better. I swear I looked on the mailing list first…
November 26th, 2008 at 10:15
[...] vamos, porno duro. Me defiendo con PHP también (últimamente me está gustando CakePHP, aunque la documentación no es lo mejor) así que lo único que me falta para ser un hombre orquesta total es diseñar, pero en eso sí que [...]
December 2nd, 2008 at 20:05
Buenas Zárate, In english (a ver si me sale , jeje)
Once upon a time my laziness took me to cakephp. I use cakephp for admin flash driven sites. I use cakeamfphp to connect width the controllers.
For admin area authentication I use a component, I can´t remember where I found it:
then each controller has a:
var $components=array(‘login’);
i know this is not quite efficiency but it works. Every action in the controller like “admin_…” will ask for user and pass.
December 2nd, 2008 at 20:47
Hi Juanma!
Thanks for code snippet, might come handy in the (near) future. I’m seriously thinking about writing that Cake authentication tuto including remember-me cookies and forgot password features, because which website doesn’t have such basic features these days?