我在yii中的复选框有一个小问题。我有模态弹出窗口,我有更新的表单。 这是我的控制器:
public function actionUpdateroomrow(){
$model = Rooms::findOne($_POST['id']);
$model -> room_number_of_people = $_POST['room_number_of_people'];
$model -> room_name = $_POST['room_name'];
if(isset($_POST['room_air_conditioning']))
$model -> room_air_conditioning = $_POST['room_air_conditioning'];
else $model -> room_air_conditioning = false;
$model->update();
if (isset ($_POST['room_multimedia_id'])){
foreach($_POST['room_multimedia_id'] as $key => $value){
$model2 = RoomMultimediaData::findOne($value);
$model2 -> room_multimedia_data_value = $key;
var_dump($model2 -> errors);
}
}
$this->redirect('index');
}
哪里有问题?在这一行。
<div class="form-group">
<?php foreach($room_multimedia as $rm){ ?>
<label><?= $rm->room_multimedia_title ?></label><input type="checkbox" name="room_multimedia_id[<?= $rm->Checkmultimediadata($room->room_id,$rm->room_multimedia_id)->room_multimedia_data_id ?>]" value="<?= $rm->room_multimedia_id ?>"/>
<?php } ?>
</div>
这是来自更新公式的行,我不确定,我失败了。 在RoomMultimedia.php中,modul我有这个:
public function Checkmultimediadata($room_id,$room_multimedia){
return RoomMultimediaData::find()->where('room_id='.$room_id.' and room_multimedia_id='.$room_multimedia.'')->one();
}
来自yii的警告:
PHP Warning – yii\base\ErrorException
Creating default object from empty value
$model2 -> room_multimedia_data_value = $key;
你可以帮我解决这个问题吗?
谢谢你们! :)