Actually, you had the right idea already. If User hasOne Profile and
Profile belongsTo User, then Profile will have user_id and User will
not have profile_id. However, you could pass just the User.id as
before and get the Profile.id in the action that your link points to.

view:

echo $html->image(
        'cog.png',
        array(
                'alt' => 'Edit',
                'title' => 'Edit',
                'url' => array(
                        'controller' => 'users',
                        'action' => 'edit',
                        $session->read('Auth.User.id')
                )
        )
);

controller:

function edit($user_id = null)
{
        if (!is_null($user_id))
        {
                $profile_id = $this->Profile->find('first', 
array('Profile.user_id'
=> $user_id));
                ...
                
                
        }
}

or:

function edit($user_id = null)
{
        if (!is_null($user_id))
        {
                $profile = $this->Profile->find(
                        'first',
                        array(
                                'conditions' => array('Profile.user_id' => 
$user_id)
                        )
                );
                ...
        }
}

On Wed, Aug 26, 2009 at 4:39 PM, paulos nikolo<paulitosthe...@gmail.com> wrote:
> Sry Brian you are right!The relations are: User HasOne Profile and Profile
> belongsTo User.In profiles table i use the user_id field but in users i
> didn't use the profile_id.So in order to make your solution work i must add
> a field with that name,if there is not any other soluton.
>
> Many thanks for your post Brian!
>
> 2009/8/26 brian <bally.z...@gmail.com>
>>
>> Use $session->read('Auth.User.profile_id') *if* your User model has
>> that field. You haven't explained how the association between User &
>> Profile has been set up, so it's difficult to say.
>>
>> On Wed, Aug 26, 2009 at 12:01 PM, Paulos23<paulitosthe...@gmail.com>
>> wrote:
>> >
>> > Hello people,
>> > I am facing a small problem here.To get you to the point i have 2
>> > models User,Profile and their controllers as well.I have set up the
>> > relations and then i created an element which appears when user logs
>> > in.In the element i have put options in order to view,edit User
>> > details and Profile details.I have managed to pass the id of user from
>> > the view like this  ---->
>> >
>> > <?php echo $html->image("cog.png",array("alt" =>
>> > "Edit","title"=>"Edit",'url' => array('controller' => 'users',
>> > 'action' => 'edit',$session->read('Auth.User.id'))));?>
>> >
>> > and now i want to pass the profile id but when i do ----->
>> >
>> > <?php echo $html->image("user_go.png",array("alt" =>
>> > "View" ,"title"=>"View",'url' => array('controller' => 'profiles',
>> > 'action' => 'view',$user['Profile']['id'])));?>  i take 2 errors that
>> > user and profile variables are not defined.
>> > How can I take the profile id to pass it to the profiles_controller
>> > like in the users above??
>> > Is there any way to do it?
>> >
>> > Ty very much in advance!
>> > >
>> >
>>
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to