这下面的代码在ViewModel里提交的时如果验证不通过应该输出验证错误的信息(XX不能为空这样的验证信息),可是实际上没有输出,也没有任何异常,只是刷新了一下页面。
public function actionIndex()
{
$this->mySave();
$model = new myModel();
$resource = new CActiveDataProvider('myModel');
$this->render('viewModel', array('dataProvider' => $resource , 'model' => $model;
}
private function mySave()
{
$model = new myModel();
if (isset($_POST['myModel'])) {
$model->attributes = $_POST['myModel'];
if ($model->save())
{
$this->redirect(array('viewModel' , 'id' => $model->Id));
}
}
}
这下面的两段都是可以的,对这个问题感到迷茫,所以特来问问
public function actionIndex()
{
$model = new myModel();
$this->mySave($model);
$resource = new CActiveDataProvider('myModel');
$this->render('viewModel', array('dataProvider' => $resource , 'model' => $model;
}
private function mySave($model=null)
{
$model = $model==null?new myModel():$model;
if (isset($_POST['myModel'])) {
$model->attributes = $_POST['myModel'];
if ($model->save())
{
$this->redirect(array('viewModel' , 'id' => $model->Id));
}
}
}
public function actionIndex()
{
$model = new myModel();
if (isset($_POST['myModel'])) {
$model->attributes = $_POST['myModel'];
if ($model->save())
{
$this->redirect(array('viewModel' , 'id' => $model->Id));
}
}
$resource = new CActiveDataProvider('myModel');
$this->render('viewModel', array('dataProvider' => $resource , 'model' => $model;
}
不知道上面的问题有没有遇到过的。我觉得原因是我的mySave方法里有一个new myModel,然后在actionIndex里也有一个new myModel,但为什么产生这个问题我不明白
谢谢
PHP5.3.1,yii-docs-1.1rc.r1585