繁体   English   中英

模型保存在yii中不起作用,并且不重定向到查看页面

[英]model save is not working in the yii and it is not redirecting to view page

我在控制器中使用以下代码。 看一看,让我知道这个问题。

$model = new Model;

if (isset($_POST['Model'])) {  
    if ($model->save) {
        $this->redirect(array('view','id'=>$model->id));
    }
}

我可以假设,您可以尝试以下更改:

$model= new Model();
if(isset($_POST['Model'])){
    $model->attributes = $POST['Model']
    if($model->save)
        $this->redirect(array('view','id'=>$model->id));
}
$model= new Model();

if(Yii::app()->request->isPostRequest)
{
    $model->attributes = $_POST['Model']

    if($model->save)
        $this->redirect(array('view','id'=>$model->id));
}

您的代码存在一些问题。 首先,您没有设置模型的值。 第二。 保存是一个函数,而不是一个变量

$model = new Model;

if (isset($_POST['Model'])) {
    // Fix 1. Save the details from the form to your model
    $model->setAttributes = $_POST['Model'];
    // Fix 2. Save is a function. Notice the ()
    if ($model->save()) {
        $this->redirect(array('view','id'=>$model->id));
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM