Stuart ha escrito:

> I've just been looking into Cake and noticed that the model methods
> return arrays rather than objects and that in version 2 this will
> change so that model data will be encapsulated in objects. Fair enough.
>
> I was wondering if anyone had any thoughts on how to write code that
> would require the least amount of modification to migrate to version 2.
>
> Also, in version 1.x, what would be the best way to implement something
> like Person->getAge() where Person is a bean-type model object with a
> field for birthdate but not age and getAge uses the current date to
> compute the age from the birthdate?
>
I'm sure that this isn't the best version, but I do:

function getAge($id=null)
{
    if($id===null) $id=$this->id;
    $data=$this->findById($id);
    if (!$data) return null;
    return calculate_age($data['Person'][birthdate');
}
> Cheers,
> Stuart


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to