Quantcast

Problem with hasOne Relation

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem with hasOne Relation

Raphi
Hi there,

I'm new to Cake and now I seem to have a little understanding problem.
The situation is this:

I have a UsersController and a User Model. Then there is an
editProfile() method within my UsersController. Of course I also
created a view (users/edit_profile.ctp). My problem is that I want to
have an editable automagic form on that page that is linked to the
user_profiles table.

What I did is, I added "var $hasOne = array('UserProfile');" to my
User Model. And I created a form like this:

    echo $form->create('UserProfile');
    echo $form->input('id');
    echo $form->input('name');
    echo $form->end();

Then I created a user_profile.php model file and added "var $belongsTo
= 'User';" to it. The user_profiles table has a "user_id" foreign key.

When I send the form, cake throws an error as it cannot find the
"UserProfileController". Normally this would be ok but for I want the
UsersController to do all the work it's not. What can I do? I mean, I
could create a user_profiles_controller.php to send the form and
afterwards do a redirect to the form but that wouldn't be very
fashionable.

I hope you can help me out.

Regards

Raphi

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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

lowpass
On Sun, Oct 3, 2010 at 2:01 PM, Raphi <[hidden email]> wrote:

> Hi there,
>
> I'm new to Cake and now I seem to have a little understanding problem.
> The situation is this:
>
> I have a UsersController and a User Model. Then there is an
> editProfile() method within my UsersController. Of course I also
> created a view (users/edit_profile.ctp). My problem is that I want to
> have an editable automagic form on that page that is linked to the
> user_profiles table.
>
> What I did is, I added "var $hasOne = array('UserProfile');" to my
> User Model. And I created a form like this:
>
>    echo $form->create('UserProfile');
>    echo $form->input('id');
>    echo $form->input('name');
>    echo $form->end();
>
> Then I created a user_profile.php model file and added "var $belongsTo
> = 'User';" to it. The user_profiles table has a "user_id" foreign key.
>
> When I send the form, cake throws an error as it cannot find the
> "UserProfileController". Normally this would be ok but for I want the
> UsersController to do all the work it's not. What can I do? I mean, I
> could create a user_profiles_controller.php to send the form and
> afterwards do a redirect to the form but that wouldn't be very
> fashionable.

Assuming that the data you want to modify are in the users table, and
that you want to submit the form with AJAX, you can handle it all with
a single action in UsersController.

AppController:

public $components = array('Auth', 'Session', 'RequestHandler', ...);

function beforeFilter()
{
        parent::beforeFilter();
       
        // ...
       
        if ($this->RequestHandler->isAjax())
        {
                Configure::write('debug', 0);
                $this->layout = 'ajax';
        }
}

UsersController:

function beforeFilter()
{
        parent::beforeFilter();
       
        // ...
       
        if ($this->RequestHandler->isAjax())
        {
                $this->viewPath = 'elements/users';
        }
}

public function edit()
{
        $id = $this->Auth->user('id');
       
        if (!$id)
        {
                $this->flash('invalid request');
        }
       
        if (!empty($this->data))
        {
                if ($this->User->save($this->data))
                {
                        if ($this->RequestHandler->isAjax())
                        {
                                $this->render('profile');
                        }
                }
                else
                {
                        if ($this->RequestHandler->isAjax())
                        {
                                $this->render('form');
                        }
                }
        }
        else
        {
                $this->data = $this->User->read(null, $id);
        }
       
        // set whatever else you need
}

views/elements/users/form.ctp:


<?php
if (!empty($form->validationErrors))
{
?>
        <p class="Error">There was an error in the submission. Please review
the fields below.</p>
<?php
}
?>
        <p class="Required">* Required Field</p>
<?php

switch ($this->params['action'])
{
        case 'admin_add':
       
                echo $form->create('User', array('action' => 'add', 'admin' => 1));
                break;
               
        case 'add':
       
                echo $form->create('User', array('action' => 'add'));
                break;
               
        case 'admin_edit':
       
                echo $form->create('User', array('action' => 'edit', 'admin' => 1));
                echo $form->hidden('User.id');
                break;
               
        case 'edit':
       
                echo $form->create('User', array('action' => 'edit'));
                echo $form->hidden('User.id');
                break;
}

In the case blocks above, you could include your JS link(s) for the
AJAX form stuff. You can also switch on $this->params['action'] for
the submit buttons, test it for whether to include certain fields,
etc. The add, edit, admin_add, admin_edit views all just include the
form element.

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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

Raphi
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. :(


On 3 Okt., 22:36, cricket <[hidden email]> wrote:

> On Sun, Oct 3, 2010 at 2:01 PM, Raphi <[hidden email]> wrote:
> > Hi there,
>
> > I'm new to Cake and now I seem to have a little understanding problem.
> > The situation is this:
>
> > I have a UsersController and a User Model. Then there is an
> > editProfile() method within my UsersController. Of course I also
> > created a view (users/edit_profile.ctp). My problem is that I want to
> > have an editable automagic form on that page that is linked to the
> > user_profiles table.
>
> > What I did is, I added "var $hasOne = array('UserProfile');" to my
> > User Model. And I created a form like this:
>
> >    echo $form->create('UserProfile');
> >    echo $form->input('id');
> >    echo $form->input('name');
> >    echo $form->end();
>
> > Then I created a user_profile.php model file and added "var $belongsTo
> > = 'User';" to it. The user_profiles table has a "user_id" foreign key.
>
> > When I send the form, cake throws an error as it cannot find the
> > "UserProfileController". Normally this would be ok but for I want the
> > UsersController to do all the work it's not. What can I do? I mean, I
> > could create a user_profiles_controller.php to send the form and
> > afterwards do a redirect to the form but that wouldn't be very
> > fashionable.
>
> Assuming that the data you want to modify are in the users table, and
> that you want to submit the form with AJAX, you can handle it all with
> a single action in UsersController.
>
> AppController:
>
> public $components = array('Auth', 'Session', 'RequestHandler', ...);
>
> function beforeFilter()
> {
>         parent::beforeFilter();
>
>         // ...
>
>         if ($this->RequestHandler->isAjax())
>         {
>                 Configure::write('debug', 0);
>                 $this->layout = 'ajax';
>         }
>
> }
>
> UsersController:
>
> function beforeFilter()
> {
>         parent::beforeFilter();
>
>         // ...
>
>         if ($this->RequestHandler->isAjax())
>         {
>                 $this->viewPath = 'elements/users';
>         }
>
> }
>
> public function edit()
> {
>         $id = $this->Auth->user('id');
>
>         if (!$id)
>         {
>                 $this->flash('invalid request');
>         }
>
>         if (!empty($this->data))
>         {
>                 if ($this->User->save($this->data))
>                 {
>                         if ($this->RequestHandler->isAjax())
>                         {
>                                 $this->render('profile');
>                         }
>                 }
>                 else
>                 {
>                         if ($this->RequestHandler->isAjax())
>                         {
>                                 $this->render('form');
>                         }
>                 }
>         }
>         else
>         {
>                 $this->data = $this->User->read(null, $id);
>         }
>
>         // set whatever else you need
>
> }
>
> views/elements/users/form.ctp:
>
> <?php
> if (!empty($form->validationErrors))
> {
> ?>
>         <p class="Error">There was an error in the submission. Please review
> the fields below.</p>
> <?php}
>
> ?>
>         <p class="Required">* Required Field</p>
> <?php
>
> switch ($this->params['action'])
> {
>         case 'admin_add':
>
>                 echo $form->create('User', array('action' => 'add', 'admin' => 1));
>                 break;
>
>         case 'add':
>
>                 echo $form->create('User', array('action' => 'add'));
>                 break;
>
>         case 'admin_edit':
>
>                 echo $form->create('User', array('action' => 'edit', 'admin' => 1));
>                 echo $form->hidden('User.id');
>                 break;
>
>         case 'edit':
>
>                 echo $form->create('User', array('action' => 'edit'));
>                 echo $form->hidden('User.id');
>                 break;
>
> }
>
> In the case blocks above, you could include your JS link(s) for the
> AJAX form stuff. You can also switch on $this->params['action'] for
> the submit buttons, test it for whether to include certain fields,
> etc. The add, edit, admin_add, admin_edit views all just include the
> form element.

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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

Hank
In reply to this post by Raphi
echo $form->create('UserProfile');

to

echo $form->create('UserProfile',array('controller' => 'users',
'action' => 'editUser'));

On Oct 3, 11:01 am, Raphi <[hidden email]> wrote:

> Hi there,
>
> I'm new to Cake and now I seem to have a little understanding problem.
> The situation is this:
>
> I have a UsersController and a User Model. Then there is an
> editProfile() method within my UsersController. Of course I also
> created a view (users/edit_profile.ctp). My problem is that I want to
> have an editable automagic form on that page that is linked to the
> user_profiles table.
>
> What I did is, I added "var $hasOne = array('UserProfile');" to my
> User Model. And I created a form like this:
>
>     echo $form->create('UserProfile');
>     echo $form->input('id');
>     echo $form->input('name');
>     echo $form->end();
>
> Then I created a user_profile.php model file and added "var $belongsTo
> = 'User';" to it. The user_profiles table has a "user_id" foreign key.
>
> When I send the form, cake throws an error as it cannot find the
> "UserProfileController". Normally this would be ok but for I want the
> UsersController to do all the work it's not. What can I do? I mean, I
> could create a user_profiles_controller.php to send the form and
> afterwards do a redirect to the form but that wouldn't be very
> fashionable.
>
> I hope you can help me out.
>
> Regards
>
> Raphi

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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

Raphi
Hi that doesn't work. Cake takes the array and outputs it as html
attributes to the form tag:

echo $form->create('UserProfile',array('controller' => 'users',
'action' => 'editUser'));

gives me:

<form controller="users" ......

Changing the action attribute of the form tag manually doesn't work as
well. It doesn't matter what I write into the ('action' => 'xxxx')
array the controller seems to be predefined by conventions. So a
create('UserProfile') form will always require a
users_profile_controller. (?)


On 4 Okt., 06:03, Hank <[hidden email]> wrote:

> echo $form->create('UserProfile');
>
> to
>
> echo $form->create('UserProfile',array('controller' => 'users',
> 'action' => 'editUser'));
>
> On Oct 3, 11:01 am, Raphi <[hidden email]> wrote:
>
> > Hi there,
>
> > I'm new to Cake and now I seem to have a little understanding problem.
> > The situation is this:
>
> > I have a UsersController and a User Model. Then there is an
> > editProfile() method within my UsersController. Of course I also
> > created a view (users/edit_profile.ctp). My problem is that I want to
> > have an editable automagic form on that page that is linked to the
> > user_profiles table.
>
> > What I did is, I added "var $hasOne = array('UserProfile');" to my
> > User Model. And I created a form like this:
>
> >     echo $form->create('UserProfile');
> >     echo $form->input('id');
> >     echo $form->input('name');
> >     echo $form->end();
>
> > Then I created a user_profile.php model file and added "var $belongsTo
> > = 'User';" to it. The user_profiles table has a "user_id" foreign key.
>
> > When I send the form, cake throws an error as it cannot find the
> > "UserProfileController". Normally this would be ok but for I want the
> > UsersController to do all the work it's not. What can I do? I mean, I
> > could create a user_profiles_controller.php to send the form and
> > afterwards do a redirect to the form but that wouldn't be very
> > fashionable.
>
> > I hope you can help me out.
>
> > Regards
>
> > Raphi

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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

lowpass
In reply to this post by Raphi
On Sun, Oct 3, 2010 at 4:49 PM, Raphi <[hidden email]> 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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

Raphi
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 <[hidden email]> wrote:

> On Sun, Oct 3, 2010 at 4:49 PM, Raphi <[hidden email]> 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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

lowpass
On Fri, Oct 8, 2010 at 1:41 PM, Raphi <[hidden email]> 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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
and
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

and
In reply to this post by Raphi
Sometimes, if you use both 'hasOne' and 'belongsTo' it doesn't work. I
experienced it very often. Try just to use one of them.
And the second point is that, if you have typed it here correctly,
your $belongsTo is not correct. $belongsTo = array('....'); but try it
without belongsTo. I had those issues also in my usermanagement where
I wanted to create a connection from the user itself to some special
properties like birthday and stuff like that.

keep going :-)

On 3 Okt., 20:01, Raphi <[hidden email]> wrote:

> Hi there,
>
> I'm new to Cake and now I seem to have a little understanding problem.
> The situation is this:
>
> I have a UsersController and a User Model. Then there is an
> editProfile() method within my UsersController. Of course I also
> created a view (users/edit_profile.ctp). My problem is that I want to
> have an editable automagic form on that page that is linked to the
> user_profiles table.
>
> What I did is, I added "var $hasOne = array('UserProfile');" to my
> User Model. And I created a form like this:
>
>     echo $form->create('UserProfile');
>     echo $form->input('id');
>     echo $form->input('name');
>     echo $form->end();
>
> Then I created a user_profile.php model file and added "var $belongsTo
> = 'User';" to it. The user_profiles table has a "user_id" foreign key.
>
> When I send the form, cake throws an error as it cannot find the
> "UserProfileController". Normally this would be ok but for I want the
> UsersController to do all the work it's not. What can I do? I mean, I
> could create a user_profiles_controller.php to send the form and
> afterwards do a redirect to the form but that wouldn't be very
> fashionable.
>
> I hope you can help me out.
>
> Regards
>
> Raphi

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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

Raphi
Ahh thank you guys so much!

Adding the "url" to the form-helper did the trick. I'm using the Auth-
component so I'll use $this->Auth->user('id') to identify the user.
I also deleted the "belongsTo" statement from my user_profile model
and everything is working in the exact same way so this really isn't
necessary. It wasn't causing any problems but it's still good to know
that you don't need it for a hasOne relation, so thanks for the info!

thanks again and kind regards

Raphi


On 10 Okt., 08:38, and <[hidden email]> wrote:

> Sometimes, if you use both 'hasOne' and 'belongsTo' it doesn't work. I
> experienced it very often. Try just to use one of them.
> And the second point is that, if you have typed it here correctly,
> your $belongsTo is not correct. $belongsTo = array('....'); but try it
> without belongsTo. I had those issues also in my usermanagement where
> I wanted to create a connection from the user itself to some special
> properties like birthday and stuff like that.
>
> keep going :-)
>
> On 3 Okt., 20:01,Raphi<[hidden email]> wrote:
>
> > Hi there,
>
> > I'm new to Cake and now I seem to have a little understanding problem.
> > The situation is this:
>
> > I have a UsersController and a User Model. Then there is an
> > editProfile() method within my UsersController. Of course I also
> > created a view (users/edit_profile.ctp). My problem is that I want to
> > have an editable automagic form on that page that is linked to the
> > user_profiles table.
>
> > What I did is, I added "var $hasOne = array('UserProfile');" to my
> > User Model. And I created a form like this:
>
> >     echo $form->create('UserProfile');
> >     echo $form->input('id');
> >     echo $form->input('name');
> >     echo $form->end();
>
> > Then I created a user_profile.php model file and added "var $belongsTo
> > = 'User';" to it. The user_profiles table has a "user_id" foreign key.
>
> > When I send the form, cake throws an error as it cannot find the
> > "UserProfileController". Normally this would be ok but for I want the
> > UsersController to do all the work it's not. What can I do? I mean, I
> > could create a user_profiles_controller.php to send the form and
> > afterwards do a redirect to the form but that wouldn't be very
> > fashionable.
>
> > I hope you can help me out.
>
> > Regards
>
> >Raphi

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 [hidden email]
To unsubscribe from this group, send email to
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with hasOne Relation

Jonathan Sibley
Hey Guys,

Great help... I just started with CakePHP and I'm tuning in to the
Google Group to pick up some things.  I learned a lot through this
thread.  Thanks for that.

Best,
Jonathan

On Oct 10, 2:25 pm, Raphi <[hidden email]> wrote:

> Ahh thank you guys so much!
>
> Adding the "url" to the form-helper did the trick. I'm using the Auth-
> component so I'll use $this->Auth->user('id') to identify the user.
> I also deleted the "belongsTo" statement from my user_profile model
> and everything is working in the exact same way so this really isn't
> necessary. It wasn't causing any problems but it's still good to know
> that you don't need it for a hasOne relation, so thanks for the info!
>
> thanks again and kind regards
>
> Raphi
>
> On 10 Okt., 08:38, and <[hidden email]> wrote:
>
> > Sometimes, if you use both 'hasOne' and 'belongsTo' it doesn't work. I
> > experienced it very often. Try just to use one of them.
> > And the second point is that, if you have typed it here correctly,
> > your $belongsTo is not correct. $belongsTo = array('....'); but try it
> > without belongsTo. I had those issues also in my usermanagement where
> > I wanted to create a connection from the user itself to some special
> > properties like birthday and stuff like that.
>
> > keep going :-)
>
> > On 3 Okt., 20:01,Raphi<[hidden email]> wrote:
>
> > > Hi there,
>
> > > I'm new to Cake and now I seem to have a little understanding problem.
> > > The situation is this:
>
> > > I have a UsersController and a User Model. Then there is an
> > > editProfile() method within my UsersController. Of course I also
> > > created a view (users/edit_profile.ctp). My problem is that I want to
> > > have an editable automagic form on that page that is linked to the
> > > user_profiles table.
>
> > > What I did is, I added "var $hasOne = array('UserProfile');" to my
> > > User Model. And I created a form like this:
>
> > >     echo $form->create('UserProfile');
> > >     echo $form->input('id');
> > >     echo $form->input('name');
> > >     echo $form->end();
>
> > > Then I created a user_profile.php model file and added "var $belongsTo
> > > = 'User';" to it. The user_profiles table has a "user_id" foreign key.
>
> > > When I send the form, cake throws an error as it cannot find the
> > > "UserProfileController". Normally this would be ok but for I want the
> > > UsersController to do all the work it's not. What can I do? I mean, I
> > > could create a user_profiles_controller.php to send the form and
> > > afterwards do a redirect to the form but that wouldn't be very
> > > fashionable.
>
> > > I hope you can help me out.
>
> > > Regards
>
> > >Raphi

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