Here's how I do it, I'm no cake guru, but it works...

Create your "Add Child" link in the Parent view like this:

$html->link("Add Child", array("controller"=>"ChildControllerName",
"action"=>"add", "parent_id"=>id_of_the_parent));

(creates a link that passes the parent id to the child controller's
add method)



In the child's add view:

if (isset($this->params['pass']['parent_id'])) {

        $parent_id = $this->params['pass']['parent_id'];

}
else {

        $parent_id = null;

}

And update the form field that points back to the parent to auto
select the parent:

echo $form->input('parent_id',array('class'=>'input', "selected"=>
$parent_id));

You can add an additional parameter to the $form->input to hide the
field (or use a hidden field instead)

Hope this helps.



On Nov 23, 3:37 pm, WordPress Guru <[EMAIL PROTECTED]> wrote:
> I dont know if the group is moderated. My previous mail did not appear
> here so I am posting again.
> --------------------
> Here is my problem , which is very similar to yours Julian.
>
> I have a parent-child relationship , and as usual I have baked the
> controllers and views using scaffolding. Like you I want to enforce
> referential integrity. For this I have placed a link to add a child in
> the parents view. The following link appears in view where parents
> details are listed.
>
> /child/addToParent/1
>
> where 1 is the id of the parent to which the child will be added. Now
> I have written a controller in the child named addToParent($id) and a
> corresponding view add_to_parent.thtml to show the form.
>
> Now in the controller function I can see the value of id is apearing
> correctly. What I cant do here is to set the id of the foreign key
> parent_id to id. I tried the following just before the save, which did
> not worked.
>
>  $this->data['parent_id']=$id
>
> So my question is how can I set the foreign key.
>
> The other thing I would ask is if there is a god tutorial that
> describes the anatomy of cake. That will be grate. I am encountering
> the problem becasue I dont know the basic anatomy and ways to
> manipulate data in deifferent areas. All I could find is the manual at
> cakephp.
>
> Regards
>
> --------------------
>
> On Nov 22, 11:23 am, julian <[EMAIL PROTECTED]> wrote:
>
> > AD thanks for the input,  I believe I was misleading in my
> > terminology,  I see I used the proase scafolding.  what i meand was
> > the "standard views " you geat when you bake a view and specify no
> > scafolding
>
> > once again sorry for mixing up my terms
>
> > Julian
>
> > On Nov 22, 12:41 pm, AD7six <[EMAIL PROTECTED]> wrote:
>
> > > You don't, you write an application. Have a look at baking none-
> > > scaffolding controllers/views, and edit what you get out.
>
> > > hth,
>
> > > AD
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to