我有一个名为人 strong>的表, id strong>和< strong>名称 strong>字段。 p>
我有一个 create.php strong>视图,可以加载名为人员 strong>的模型,现在我 想要添加一个名为 hasCar strong>的复选框来显示一个人是否有车(因此它是一个布尔条件)。 p>
然后我有发送 strong>按钮,将表单 strong>的 $ model strong>数组发送到控制器,因此我需要将 hasCar strong>变量添加到 $ model strong>数组。 p>
但是复选框不是人员 strong>表的列,所以我遇到了一些错误,因为它不是模型的一部分。 p>
\ n 我以这种方式添加了复选框,但它当然不起作用。 p>
是否可以在 $ model strong>数组中发送 hasCar strong>变量? 我的意思是,当按下发送 strong>按钮时,如何将 hasCar strong>变量发送到控制器? p>
div>
&lt;?= $ form-&gt; field($ model,'hasCar “) - &GT;复选框(); ?&gt;
code> pre>
I have a table called persons with id and name fields.
I have a create.php view that loads the model called Persons and now I want to add a checkbox called hasCar to show if a person has a car (so it is a boolean condition).
Then I have the send button that send the $model array of the form to the controller so I need to add the hasCar variable to $model array.
But the checkbox is not a column of the persons table so I got some errors because it is not part of the model.
I added the checkbox in this way but it is not working, of course.
<?= $form->field($model, 'hasCar')->checkbox(); ?>
Is it possible to send the hasCar variable inside the $model array? I mean, how can I send the hasCar variable to the controller when the send button is pressed?