Thanks a ton for your response Paul. Being able to do a saveAll would
be awesome and it looks like it would definitely shorten my code up
substantially. But, if it requires me using checkboxes for the
subjects/tags it's a no go. When instructors are registering they need
to be able to type in their subjects. This way if their subject
doesn't exist in the DB it'll be added. I did it this way so that I
didn't have to have checkboxes, but then also have another field for
"if you don't see yours listed add one".

When instructors type their subjects into the form field with commas
separating each, the subjects are then exploded and trimmed and saved
separately. I actually figured out how to do that part with the help
of the link you posted. I've used this method before as well but it
didn't involve a user and an profile as well as tags. It was just
saving a post and tags at the same time.

I think you've sparked something and I'll have to give it a try and
report back.

In the mean time, if anyone can tell me why Cake thinks that a
zip_code and a phone number are instructor_id's that can be used in my
join table, that would be great.

Thanks,
Jonathan

On Jun 8, 6:44 am, WebbedIT <[email protected]> wrote:
> If you structure your data array correctly you could use one saveAll
> command on the instructor table and the 3 models would save.  So your
> save code would be reduced to:
>
> if (!empty($this->data)) {
>   if ($this->User->Instructor->saveAll($this->data,
> array('validate'=>'first'))) {
>     $this->Session->setFlash('User saved');
>     $this->redirect(array('action'=>'view', $this->User->id));
>   } else {
>     $this->Session->setFlash('Usernot saved');
>   }
>
> }
>
> To do this, you need to get your head around how to use Cake's
> automagic to retrieve your HABTM subjects and display them as a
> multiple select or checkbox list in your form so the resulting data
> structure ends up looking something like
>
> Array
> (
>     [User] => Array
>         (
>             [username] => MrInstructor
>             [password] => cddb06c93c72f34eb9408610529a34645c29c55d
>             [group_id] => 2
>         )
>
>     [Instructor] => Array
>         (
>             [name] => Jimmy Bob
>             [email] => [email protected]
>             [phone] => 1112223333
>             [city] => Beverly Hills
>             [zip_code] => 90210
>             [states] => 5
>             [website] =>www.jimmybobschool.com
>             [description] => Jimmy Box is an instructor.
>             [user_id] => 1
>             [id] => 1
>         )
>
>     [Subject] => Array
>         (
>             [Subject] => Array
>             (
>                 [0] => 15 // id for hitting
>                 [1] => 21 // id for pitching
>             )
>         )
> )
>
> Not read through this blog post fully, but may be of some 
> help:http://mrphp.com.au/code/working-habtm-form-data-cakephp
>
> HTH
>
> Paul.

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

Reply via email to