Check this out :
http://bakery.cakephp.org/articles/view/202
On Mar 24, 6:40 pm, "nnichols" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I was wondering if anyone knew a neat way to use the html helper to
> handle forms that allow for the adding/editing of a main model and
> it's associated entries in a hasMany associated model.
>
> For example, I have a User model which hasOne AccountProfile and
> hasMany AccountMembers.
>
> In my UsersController's add method I have some code similar to this -
>
> $errors = false;
>
> if (!$this->User->validates($this->data)) {
> $errors = true;}
>
> if (!$this->AccountProfile->validates($this->data)) {
> $errors = true;}
>
> foreach ($this->data['AccountMember'] as $AccountMember) {
> if (!$this->User->AccountMember->validates($AccountMember)) {
> $errors = true;
> }
>
> }
>
> if (!$errors) {
> $this->User->save($this->data, false);
> $this->data['AccountProfile']['user_id'] = $this->User->id;
> $this->AccountProfile->save($this->data, false);
> foreach ($this->data['AccountMember'] as $AccountMember) {
> $this->User->AccountMember->create();
> $AccountMember['user_id'] = $this->User->id;
> $this->User->AccountMember->save($AccountMember, false);
> }
>
> }
>
> Is this the best way to do this multi-model save of is there a cake
> way of dealing with it such that I don't need to run the validation
> separately?
>
> For the User and AccountProfile models I can use the html helper to
> create input fields but I can't seem to find a way to create input
> fields for the multiple AccountMember model entries. I just wanted to
> check if I was missing something and if anyone knew of a way to handle
> this before I start writing my own code to handle it?
>
> Nick
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---