Issue
I have just started learning cakephp3, so please excuse me for anything wrong. So I have one table called Projects and Events, so there relation is like one project can have many events.
When the user is adding a new project, he will be redirected to 'add' event in Controller 'events '.
testapp/projects/add --> testapp/events/add
The code in default add.ctp has a dropdown of projects but i want it to be the normal text field with the value of just created project instead of dropdown.
Please tell how can I achieve this?
Thanks in advance
Solution
somewhere in your ProjectsController
you shoud have something like
redirect(['action' => 'add', 'controller' => 'Events'])
and you should have a variable named $project
storing a ProjectEntity
just pass the project id to the redirect action
redirect(['action' => 'add', 'controller' => 'Events', $project->id])
then in your EventsController
you'll read the value and store it to the Event entity this way
function add($project_id)
{
// Do something
$event = $this->Events->newEntity();
$event->project_id = $project_id;
// do something else
}
Answered By - arilia Answer Checked By - David Goodson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.