On Fri, Oct 8, 2010 at 1:41 PM, Raphi <[email protected]> wrote:
> Ok let me try to explain.
>
> I have two tables involved: users, user_profiles
>
> Of course there is a model-file to any of the tables so: user.php,
> user_profile.php
> The models are linked via a "hasOne"(parent key user_id) relationship.
> (which is working perfectly).
>
> But now I want to implement a method that gives users the possibility
> to alter their own profiles. Therefore I created an "editProfile"
> method in the UsersController and a corresponding view-file
> "edit_profile.ctp" in views/users.
>
> Within this view-file I created a form using the formhelper:
>
> echo $form->create('UserProfile');
> echo $form->input('id');
> echo $form->input('name');
> echo $form->end('Save changes');
>
> That is great because creating the form using "$form-
>>create('UserProfile');" makes it automatically fill in the values
> from the database. My problem occurs when it comes to submitting the
> form. Cake recognizes the "UserProfile" model and tries to use the
> "UserProfileController" which does not exist. I want to use the
> UsersController to do that job. I mean I know I could use "$form-
>>create('User');" in order to get it working but that makes it
> impossible for cake to fill out the form automatically. I don't really
> get why using the "User" model doesn't work. For there is an existing
> relationship the "User" model should be able to pass on the
> user_profiles datas.
>
First, the reason why you ended up with <form controller="users" is
because you gave 'controller' as an aoption. You can do this, but not
the way that you did. The method takes a model name, plus an array of
options. The ones we're interested in are 'action' and 'url'. The
latter one takes as a value an array and it's in that array that you'd
supply 'controller'. So you had 'controller' one level up. Make sense?
Anyway, so you have a UserProfile model and table but you want to do
the action in UsersController. You can either get rid UserProfile
altogether and put all of its data in users table or you can do
something like:
echo $this->Form->create('UserProfile', array('url' =>
array('controller' => 'users', 'action' => 'editProfile'));
echo $this->Form->hidden('UserProfile.user_id');
Or, you can leave out user_id and add it to $this->data in the action,
using $this->Session->user('id'); That way, there's no chance that
someone can fiddle with the form element values.
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