我正在开发一个允许用户举行视频会议的web应用程序。用户可以创建视频会议,我希望他们也能够编辑预定的视频会议,但我有困难实现这一点。请帮帮忙。
index.php视图中的编辑按钮
$html .= CHtml::ajaxLink('Edit',
Yii::app()->createAbsoluteUrl('videoConference/update/'.$vc->id),
array(
'type'=>'post',
'data' => array('id' =>$vc->id,'type'=>'update'),
),
array( "visible" => $ismoderator, 'role' => "button", "class" => "btn btn-info")
);视频会议控制器actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
if (isset($_POST['VideoConference'])) {
$model->attributes = $_POST['VideoConference'];
if ($model->save())
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('edit', array(
'model' => $model,
));
}发布于 2015-06-01 21:45:14
经过一点故障排除后,我终于开始工作了。在视图中,我调用的actionUpdate方法如下:
$html .= CHtml::button('Edit', array('submit' => array('videoConference/update/'.$vc->id), "visible" => $ismoderator, 'role' => "button", "class" => "btn btn-info"));刚换了控制器
$model->save() to $model->update()而且效果很好。
发布于 2015-06-01 15:28:03
第一步是找出问题所在(前端/后端)。您需要在不使用ajax的情况下调用操作(只需使用param id的url )。试试我的版本:
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
if ($model == null) {
throw new CHttpException(404, 'Model not exist.');
}
//if (isset($_POST['VideoConference'])) {
//$model->attributes = $_POST['VideoConference'];
$model->attributes = array('your_attr' => 'val', /* etc... */);
// or try to set 1 attribute $model->yourAttr = 'test';
if ($model->validate()) {
$model->update(); //better use update(), not save() for updating.
$this->redirect(array('view', 'id' => $model->id));
} else {
//check errors of validation
var_dump($model->getErrors());
die();
}
//}
$this->render('edit', array(
'model' => $model,
));
}如果在服务器端所有工作正常(行已被更新),则检查请求参数、控制台、令牌等。问题将出现在前面。
https://stackoverflow.com/questions/30574821
复制相似问题