weixin_33725722 2015-06-01 13:27 采纳率: 0%
浏览 30

在Yii框架中编辑动作

I am working on a web application that allow users to have video conferences. Users are allowed to create video conferences and I want them to be able to also edit the scheduled video conferences but I am having trouble implementing that. Please help.

Edit button in index.php view

 $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")
    );

Video conference Controller 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,
    ));

}
  • 写回答

2条回答 默认 最新

  • weixin_33697898 2015-06-01 15:28
    关注

    The first step is to find where is problem(frontend / backend). You need call action without ajax(just from url with param id). Try my version:

    /**
     * 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,
        ));
    }
    

    If on server side all working fine(row was updated) then check request params, console, tokens etc. Problem will be on frontend.

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置