Hey Bingo,
I cannot point you to a tutorial (but I am sure something is there on
the wiki).
To answer your problem (to which there can be many approaches), I can
take one example -
Suppose you have a form which has the following fields -
Username
Password
Email
Age
Country
Postal Code
The first 3 need to be entered into the 'users' table and then next
three into the 'profiles' table.
Name the first 3 input types as User/fieldname & the other 3 as
Profile/fieldname just like you would do when you are entering data
into only one table.
So, now when the user submits the form, you'll have something in the
User array & something in the profile array.
You can now make use of something called requestAction() to invoke a
method in another controller.
So, for eg, if you did a submit to the users controller (form action
being /users/add), then in that controller you could try to access the
Users array and pass it to the save method.
Once the data is saved in the users table, you want to know add the
profile data to the profile table-right?
For this inside the add method of users controller, you could check if
save was successful then call -
$this->requestAction('/profiles/add', array());
Using the above you are calling the add method of the profiles
controller from the users controller. The second argument is the array
of values you want to pass to the add method of the profiles
controller.
Now, in the profiles controllers's add method, you can grab the profile
array (passed by the form earlier) and call the save method.
Not the most optimum or best of examples (as I too am new to cake), but
I think this should get you started.
Drop me a line if this helped you :)
Regards,
Mandy.
bingo wrote:
> Hello all bakers,
>
> First, I would like to thanks all bakers for creating an excellent
> framework and also interesting and detailed tutuorials to get started
> with CakePHP. Especially, I had lot of fun and I was excited to see how
> within minutes a working application can built using scaffolding
>
> But as I am making progress, I am realizing lack of some important
> tutorials. Mainly that can tell how to build a form (view) and a
> controller (controller) that can insert/update data into multiple
> tables using models. I tried to gather relevant information using
> manual, irc, CakePHP group, and google search, but I having a hard time
> in putting all the things together. Probably, its lack of my programing
> experience and familiarity with PHP and to some extent lack of time.
>
> I would much appreciate if some baker can build a tutorial on how to
> build a form(view) and a controller to insert data into multiple
> tables. This seems to be a common problem with many novice baker.
>
> Regards
> Bingo
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---