I know this is probably simple but I have spent a lot of time trying
to figure this out and was hoping someone could assist.

I have a user model and a user_preference model.  user_preference
belongs to user.

I am in view.ctp of the user model and in the dump I have the
following array.

Array
(
    [User] => Array
        (
            [id] => 4
            [username] => bradmaxs
            [password] =>
            [first_name] => Bradley
            [last_name] => Mackenzie
            [street_address] =>
            [city] =>
            [state] =>
            [zip] =>
            [country] => USA
            [telephone] =>
            [email_address] =>
            [group_id] => 1
            [created] => 2010-05-03 17:33:54
            [updated] => 2010-05-09 19:53:35
        )

    [UserPreference] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [user_id] => 4
                    [image] => bradmaxs.jpg
                    [sex] => Male
                    [birthdate] =>
                    [hometown] => Pittsburgh
                    [introduction] =>
                    [created] => 2010-05-10 19:32:19
                    [modified] => 2010-05-13 17:33:35
                )

        )

)

To display info for the user data it baked: $user['User']['username'];
and this works great displaying the user model data.

Then I want to display the user_preference data as well.

It works great this way:

<?php foreach ($user['UserPreference'] as $userPreference): ?>
<img src="/files/img_usericon/<?php echo $userPreference['image'] ?>"
border="0" />
<p><?php echo $userPreference['birthdate'];?></p>
<p><?php echo $userPreference['hometown'];?></p>
<p><?php echo $userPreference['introduction'];?></p>
<p><?php echo $this->Html->link(sprintf(__('Edit %s', true), __('User
Preference', true)), array('controller' => 'user_preferences',
'action' => 'edit', $userPreference['id'])); ?></p>
<?php endforeach; ?>

But I want to take it out of the foreach loop and include it mixed
within the user model data.  I have a lot of other models with
relational data that I will need to do the same and I know there must
be a way to do this without foreach everytime.

I tried $user['UserPreference']['image'] and it is saying - :
Undefined index: image.

Any ideas?

Thanks in advance,

Brad

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 [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?hl=en

Reply via email to