Sunday, October 3, 2010

Re: models: fundamental question referring to member variables

Your example and explaination I understand, but what about using other
classes as member variables and not just simple values.
Let me give you an example:
The user table has a column 'birthtime', but in my page i want to show
the age in years and days of the user instead.
So i have a class 'Age':

Pseudocode:
class User(
private $Age = new Age());

So when i retrieve the data of the database i first need to set the
birthtime:
$this->Age->setBirthtime($data['User']['birthtime']);
to be then able to access to calculated years and days:

$user->getAge()->getYears();
$user->getAge()->getDays();

The same the other way round:
If i want to randomize the birthtime of the user with my solution i am
able to do it like that:
$user->getAge()->randomizeBirthtime();

But when i want to save the user of course first i have to get the
random birthtime out of its class and put it in the array:
$this->data['User']['birthtime'] = $this->Age->getBirthtime();
$this->save($this->data);

Something like that, sorry about my pseudo code.
The problem is that the most of my member varables are classes
actually to be able to randomize or do calculations with their values.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate