I have implement following code :
model code:
public function rules()
{
return [
-------------------
['message_of_day_active', 'integer'],
[['creation_date', 'message_of_day_active'], 'safe'],
----------------------------------------
];
}
controller code:
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
$model->attributes = $_POST['MessageOfDay'];
$model->creation_date= new \yii\db\Expression('NOW()');
if($_POST['MessageOfDay']['message_of_day_active']==1) {
$model->updateAll(['message_of_day_active'=>0], 'message_of_day_active =1');
$model->message_of_day_active =1;
}
if($model->save())
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
View Code:
<?= $form->field($model, 'message_of_day_active')->checkBox(['value'=>1, 'uncheckValue'=>0], ['template' => "{input} <span class='status'>&nbsp;</span>"]); ?>
when i have update record at time check box is selected but other record is updated but message_of_day_active field is set 0
when am change code for if condition is
if($_POST['MessageOfDay']['message_of_day_active']===1) {
--------------
}
at time record message_of_day_active field is set 1 update but updateAll() it not set 0 to all record
i have set message_of_day_active int(3) datatype
i have use PHP 5.5.19
Note: I have same code is use in yii 1.1.14 it work proper but yii 2.0.1 it not work.
What is problem in this code???
It is Yii2 Bug?..
please check this problem