How to describe actions after mark selected (or not selected) checkbox in Yii2?

There is a certain model, controllers, and types generated by Gii.

The form should contain a checkbox, and clicking the check box selected which should happen some which is not described in the generated action of the controller. How to do it?

Can't figure out how to make the design conditions.
August 19th 19 at 22:50
1 answer
August 19th 19 at 22:52
Solution
should happen some which is not described

great explanation of the problem.

Can't figure out how to make the design conditions.

I do understand You can not.

You think of a specific example. "it is necessary by clicking on the checkbox to open modelku" or "I need when you click on the checkbox to load the current user"
when selecting the checkbox and clicking on save the form (update or create) need to make an entry in the not associated with that model data, say id=1, user_id=1 (in the table two fields id and user_id), and if the checkbox is not selected, need to find to remove the record (after checking that it exists).

How to create a record or record udalenii I understand, I don't understand how to make the test conditions vybrannoi the checkbox on the language to human readable if(cabox selected) - Jameson_Hettinger commented on August 19th 19 at 22:55
Create in the model a property
public $mycheck;
added to rules:
['mycheck','safe'],
In the form of:
<?= $form--->field($model, 'mycheck')->checkbox(); ?>

further 2 variants, or to add to the model
public function beforeSave($insert)
{
 if (parent::beforeSave($insert)) {
 if($this->mycheck == null){
 //logic if it is not selected
}else{
 //logic if selected
}
 return true;
 } else {
 return false;
}
 }

or check in the controller:
public function actionCreate()
{
 $model = new MyModel;

 if ($model->load(Yii::$app->request->post())) {
 if($model->mycheck == null){
 //logic if it is not selected
}else{
 //logic if selected
}
 return $this->redirect(['view', 'id' => $model->id]);
 } else {
 return $this->render('create', [
 'model' => $model,
]);
}
 }
- Clark.Hane commented on August 19th 19 at 22:58
: Thanks! - Jameson_Hettinger commented on August 19th 19 at 23:01

Find more questions by tags Yii