我刚刚在Yii v 2.0.0的"基本"版本上尝试了"使用表单"教程。我一步一步地照着做,但我想出了问题。我有EntryForm模型,SiteController有actionEntry,两个视图都在那里。
错误跟踪:
1. in /usr/share/nginx/html/basic/controllers/SiteController.php at line 99
}
public function actionAbout()
{
return $this->render('about');
}
public function actionEntry()
{
$model = new EntryForm;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
// valid data received in $model
// do something meaningful here about $model ...
return $this->render('entry-confirm', ['model' => $model]);
} else {
// either the page is initially displayed or there is some validation error
2. yiibaseErrorHandler::handleFatalError()
use appmodelsEntryForm;
解决了这个问题。
SiteController.php中的基本命名空间是命名空间app\controllers。因此,您可以使用app\models\EntryForm添加在文件顶部,或使用$model=new\app/models\EntryForm()用于直接选择类别。
通过使用Gii生成不同的表来解决我的问题。然后自动生成的类并在EnterForm.php 上使用
class EntryForm扩展\yii\db\ActiveRecord