@var $model is just a comment that helps IDE to autocomplete code. Nothing more. It doesn’t set anything by itself. Model is coming from either controller or parent view via ->render() method.
Note that "create" action is called twice … one for rendering the form and the other for processing the post.
When you have clicked on “create” link of the index page, then your browser will request “create” action with get method without any parameter. And the “create” action will render the form with a model that is empty. “if” block is skipped because there’s no post parameters yet.
Then, when you have submitted the form, your browser will request "create" action with post method. Note that the action of an ActiveForm defaults to the current action. And the "create" action will now enter into "if" block and receive the post parameters to save the model.
"Update" action is at first called from the index page using get method with "id" parameter. So it will render the form with a model that has a content retrieved from the database, as sukran has just said. The rest of the procedure is quite similar to that of "create" action, so we can share the _form.php partial view for both the actions.
I understood it was comment, but I wrote this because it I thought this meant that those things written in comment are the params received by this ‘file’.
I see my mistake at the beginning. hank you for explaining me this.
I follow you until :
"the create.php render the $model to _form.php".
After this, I don’t see how the actions ‘create’ or ‘update’ are triggered…
when you say "in _form call the action create or update." what part of the code does this exactly ?
the submit button has an IF statement to label the button ‘create’ or ‘update’ wether it is a new record (if I understand well). but ‘create’ and’update’ are only labels.
So when I press the submit button, what code acts to trigger the ‘create’ action ?
How does the form ‘know’ what action to take at submit ?