Friday, October 8, 2010

Re: Problem with hasOne Relation

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.


On 4 Okt., 20:16, cricket <zijn.digi...@gmail.com> wrote:
> On Sun, Oct 3, 2010 at 4:49 PM, Raphi <panicr...@t-online.de> wrote:
> > Hi, thank you for you quick response. Unfortunately I neither do use
> > AJAX nor have the data saved in the users table. I guess I have to use
> > two controllers anyway. :(
>
> Well, perhaps you could state your problem clearer, then. What is the
> schema of the tables you are using? And explain what this means:
>
> > My problem is that I want to
> > have an editable automagic form on that page that is linked to the
> > user_profiles table.

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate