yii\base\ErrorException - Class 'app\controllers\EntryForm' not found

原创 LittleRob  2019-05-09 18:48:08  阅读 151 次 评论 0 条
摘要:

I just tried the Working with Forms tutorial on the "basic" version of Yii v 2.0.0. I followed it step by step, but I guess something is wrong. I have the EntryForm model in place, SiteController has the actionEntry and both the v

I just tried the Working with Forms tutorial on the "basic" version of Yii v 2.0.0. I followed it step by step, but I guess something is wrong. I have the EntryForm model in place, SiteController has the actionEntry and both the views are there too.

The error picture like this

Error Trace:

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 error2. yii\base\ErrorHandler::handleFatalError()

How to resolve:

1.The base namespace in SiteController.php is

namespace app\controllers;

. So you can add 

use app\models\EntryForm;

in the top of file or use 

$model = new \app\models\EntryForm();

for direct select of class.

2. Add this code 

use common\models\EntryForm;

if your model lives under common

3. Or add this code

 use app\models\EntryForm;

in SiteController.php solved it.

Make it

本文地址:https://www.myexplor.me/webuilding/155notfound.html
版权声明:本文为原创文章,版权归 LittleRob 所有,欢迎分享本文,转载请保留出处!

发表评论

还没有留言,还不快点抢沙发?