tags:

views:

46

answers:

2

After loading a model I the only way to get to the data seems to be very ugly.

$this->User->read(NULL, 49);
print $this->User->data['User']['email'];

Most frameworks have a much nicer way of accessing like

$User = new Model_User(49);
print $User->email;

Is there anyway to do this in CakePHP 1.2/3?

+1  A: 

The normal case is when you assign the result from this->read to a variable i.e.:

$user = $this->User->read(NULL, 49);
print $user['User']['email'];
Nik
oh my, \*shiver*
Xeoncross
In addition to my comment - the returned data could contain also the closest relations of the user's model. I.e. $user['Profile'] or $user['Activty'] etc.
Nik
+1  A: 

If you're looking for a more type safe way to do it, unfortunately not. All model access is based on array structures and is one of the very things that frustrated me about Cake.

nukefusion
Bummer. I noticed it also forces all related structures to be loaded at once instead of using lazy loading for model relations...
Xeoncross
@Xeoncross: It sounds like this would be unchangeable behavior, which is plain and simply wrong. A developer definitly has control over the associated data fetched. fyi bindModel, unbindModel, containable behavior.
benjamin