zen of coding

I need the first record from my table…

Let’s say you need to know when was the very first user record created.
Add a method like this to your User model (assuming you have a ‘created’ field):

[sourcecode language=’php’]
function getFirstDay() {
return $this->find(‘first’, array(
‘fields’ => array(‘created’),
‘order’ => ‘User.created ASC’));
}
[/cc]

Try in the controller: pr($this->User->getFirstDay());

Similar method can be used to get information about any other arbitrary field.

%d bloggers like this: