views:

125

answers:

1

Sorry if this question is too vague, but I'd rather not muddy it's point with my assumptions as to what may or may not actually be relevant background information.

If I create an association such as Employee belongsTo Company

When I create a view for Employee and want to display their Company name how can I simply display the company name by...

<?php echo $employee['Employee']['Company']['company_name'] ?>

or simply a custom property (if such a thing exist) such as...

<?php echo $employee['Employee']['CompanyName'] ?>

This, of course, assumes the use of...

$this->set('employee',$someEmployeeRetreivalLogicHere)

...in the Controller

+2  A: 

It should be accessible with:

<?php echo $employee['Company']['company_name'] ?>

If that doesn't work, use debug($employee); to see the array's structure.

dhofstet
Just adding: this of course requires that the record was retrieved with an appropriate `recursive` setting.
deceze
So in your example say Employee has a date property called "hired", I could access this by "$employee['Employee']['hired']" or would it be "$employee['hired']"Also the default recursive setting is 0 right?
Antilogic
@deceze: Yes, you are right, thanks for the addition.
dhofstet
@Antilogic: It would be $employee['Employee']['hired']
dhofstet
Hmm doesn't seem to be the case, I'm able to do $employee['Employee']['hired'] but not $employee['Company']['company_name']. I get a Notice (8): Undefined index: Company
Antilogic