Lets say I have 2 models "Project" and "Task" in a 1:M relationship, both have Gii generated CRUD(actions and views).
Now, when viewing a project in views/project/view.php, I want the viewer to be able to create new Tasks for the currently viewed project, directly in that view.php file. Tasks have a project_id foreign key field that would need to be filled.
I’m don’t know if I should render the current secret/create action in the project/view file somehow, or if I should generate a new form with Gii, and somehow rendering it in the project/view. Basically I don’t know what I’m doing here.
Can someone show me how to do what I mentioned above, or provide a link to a resource showing how this is done, please?
Thank you for your thoughts yiqing95. I have already got the CRUD generated for the Task model, and I currently have a link, as you described, that will allow me to create new tasks for a Project, but this loads a seperate view file for doing so.
To clarify: my goal is to have a (partial view?) form directly in the views/project/view.php file for creating new Tasks associated with the currently viewed project. In the form, I would probably just use a hiddenField to pass the project_id. I have been able to get a partial view form to show up from the views/project/view.php file: but, I have no idea how to handle the backend side of things for saving the forms data. My understanding in this area is pretty weak, and I would appreciate any advice on how to have a form for creating child objects, directly in the parents view.
I have read through this part of the definitive guide to yii: Working With Forms, but it is a bit too vague for my understanding. Could someone tell me if following this section of the guide is the proper approach for what I am trying to achieve, and maybe what major differences I should expect? Such as how I will need my form to be a partial view file. Then I can at least know what to study.