2014-05-05 31 views
0

想创建新的用户无数据保存,当我创建新的用户

我修改这个代码

public function actionCreate() { 
    $model = new Users; 

    if(isset($_POST['Users'])) { 
     if($model->load(Yii::$app->request->post())) { 
     if($model->save()){ 
      return $this->redirect(['']); 
     } 
     } 

    } else { 
     return $this->render('create', [ 
      'model' => $model, 
     ]); 
    } 

} 

,但它不保存! 怎么能找到问题?

+1

调试你的代码,并显示方法$ model-> load() – Alex

回答

0

试试这个 -

$model = new Users; if(isset($_POST['Users'])) { $model->attributes = $_POST['Users']; //instead of if($model->load(... if($model->save()){ return $this->redirect(['']); } ..... ....

$model->attributes = $_POST['Users'];将得到公布值和完美的设置$model对象,除非你$model->load([.....])被要求一些额外的代码。

因此,如@Alex所问,您需要提及$model->load()究竟做了什么。

我希望它有帮助。

0

试试这个

public function actionCreate() 
    { 
    $model = new users; 

    if ($model->load(Yii::$app->request->post()) && $model->save()) { 
     return $this->redirect(['']); 
    } else { 
     return $this->render('create', [ 
      'model' => $model, 
     ]); 
    } 
    } 

希望工程!

相关问题