Wednesday, April 29, 2009

Re: Saving Related Data

I usually handle that sort of thing like this:

echo $html->link(
'add new risk',
array(
'controller' => 'risks',
'action' => 'add',
'project_id' => $project['Project']['id'],
'admin' => 1
)
);

Router::connect(
'/admin/risks/add/:project_id',
array(
'controller' => 'risks',
'action' => 'add',
'admin' => 1
),
array(
'project_id' => '[0-9]+',
'pass' => array('project_id')
)
);

RisksController:
function admin_add($project_id = null)
{
if (!$project_id)
{
// angry flash msg ...
}
}

On Wed, Apr 29, 2009 at 6:22 AM, jake1729 <jake1729@gmail.com> wrote:
>
> I have pored over the PHP Cookbook, but to no avail.
>
> I have a table Projects which hasMany Risks.
>
> When accessing projects/view, and a user drills down to a specific
> project, they are provided a link to add a New Risk.
>
> When selecting "New Risk", user is taken the Add view for the Risk
> model.
>
> QUESTION: How can I pass the ID of the project the user drilled to the
> risks table (or even just to the Add view for Risk model)?  project_id
> is a foreign key in the risks table.
>
> =======
> This is such a simple thing, so I'm pretty sure I'm still not
> understanding the fundamentals of cakePHP... any ancillary help would
> also be appreciated.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: