I might be missing the point on this, but I am trying to echo out a HABTM开发者_开发百科 value in my index, and I cannot seem to get the data.
For example, I can echo these relationships with no issue:
<?php echo $plan['Age']['name']; ?> <br />
<?php echo $plan['Applicant']['name']; ?> <br />
As you can see from the _id recursive relation on the Plan model.
Hope my question is clear. Just not sure what to do on this. Can't seem to resolve it no matter the combination of vars I try.
For HABTM, the array is numerically indexed:
<?php echo $plan['Zip'][0]['value']; ?> <br />
<?php echo $plan['Zip'][1]['value']; ?> <br />
<?php echo $plan['Zip'][2]['value']; ?>
Since you are doing the find call on the Plan model, make sure you are defining the HABTM relationship in the Plan model, though preferably in both models.
er... unless my memory fails me. It might be this structure:
<?php echo $plan['Plan']['Zip'][0]['value']; ?> <br />
<?php echo $plan['Plan']['Zip'][1]['value']; ?> <br />
<?php echo $plan['Plan']['Zip'][2]['value']; ?>
Best bet is to use var_dump($plan)
or print_r($plan)
and examine the structure of the array.
Thank you for your assistance : ) I solved by doing this:
foreach($plan['Zip'] as $zip):
echo $zip['title']; ?>
<?php endforeach; ?>
My recursion runs deep, so I did not realize I call the Zip table direct and run an innde foreach to parse the Zip array.
精彩评论