php - Yii2 gii crud error Class 'app\models\Yii' not found -


i installed yii2 advanced template, created model news , want create crud (with gii), when click 'preview' error.
did not change else in advanced template.
i'm using wamp

 php fatal error – yii\base\errorexception class 'app\models\yii' not found      1. in c:\wamp\www\advanced\backend\models\news.php @ line 44     2. in c:\wamp\www\advanced\vendor\yiisoft\yii2-gii\generators\crud\default\search.php – yii\gii\generators\crud\generator::generatesearchlabels() @ line 18     1314151617181920212223      $searchmodelclass = stringhelper::basename($generator->searchmodelclass);     if ($modelclass === $searchmodelclass) {         $modelalias = $modelclass . 'model';     }     $rules = $generator->generatesearchrules();     $labels = $generator->generatesearchlabels();     $searchattributes = $generator->getsearchattributes();     $searchconditions = $generator->generatesearchconditions();      echo "<?php\n";     ?>      3. in c:\wamp\www\advanced\vendor\yiisoft\yii2\base\view.php – unknown() @ line 312     4. in c:\wamp\www\advanced\vendor\yiisoft\yii2\base\view.php – yii\base\view::renderphpfile() @ line 244     5. in c:\wamp\www\advanced\vendor\yiisoft\yii2-gii\generator.php – yii\base\view::renderfile() @ line 315     310311312313314315316317318319320          public function render($template, $params = [])         {             $view = new view;             $params['generator'] = $this;              return $view->renderfile($this->gettemplatepath() . '/' . $template, $params, $this);         }          /**          * validates template selection.          * method validates whether user selects existing template      6. in c:\wamp\www\advanced\vendor\yiisoft\yii2-gii\generators\crud\generator.php – yii\gii\generator::render() @ line 166     161162163164165166167168169170171          {             $controllerfile = yii::getalias('@' . str_replace('\\', '/', ltrim($this->controllerclass, '\\')) . '.php');             $searchmodel = yii::getalias('@' . str_replace('\\', '/', ltrim($this->searchmodelclass, '\\') . '.php'));             $files = [                 new codefile($controllerfile, $this->render('controller.php')),                 new codefile($searchmodel, $this->render('search.php')),             ];              $viewpath = $this->getviewpath();             $templatepath = $this->gettemplatepath() . '/views';             foreach (scandir($templatepath) $file) {      7. in c:\wamp\www\advanced\vendor\yiisoft\yii2-gii\controllers\defaultcontroller.php – yii\gii\generators\crud\generator::generate() @ line 44     3940414243444546474849              $generator = $this->loadgenerator($id);             $params = ['generator' => $generator, 'id' => $id];             if (isset($_post['preview']) || isset($_post['generate'])) {                 if ($generator->validate()) {                     $generator->savestickyattributes();                     $files = $generator->generate();                     if (isset($_post['generate']) && !empty($_post['answers'])) {                         $params['haserror'] = $generator->save($files, (array) $_post['answers'], $results);                         $params['results'] = $results;                     } else {                         $params['files'] = $files;      8. in c:\wamp\www\advanced\vendor\yiisoft\yii2\base\inlineaction.php – yii\gii\controllers\defaultcontroller::actionview() @ line 54     9. in c:\wamp\www\advanced\vendor\yiisoft\yii2\base\inlineaction.php – call_user_func_array() @ line 54     10. in c:\wamp\www\advanced\vendor\yiisoft\yii2\base\controller.php – yii\base\inlineaction::runwithparams() @ line 127     11. in c:\wamp\www\advanced\vendor\yiisoft\yii2\base\module.php – yii\base\controller::runaction() @ line 435     12. in c:\wamp\www\advanced\vendor\yiisoft\yii2\web\application.php – yii\base\module::runaction() @ line 84     13. in c:\wamp\www\advanced\vendor\yiisoft\yii2\base\application.php – yii\web\application::handlerequest() @ line 312     14. in c:\wamp\www\advanced\backend\web\index.php – yii\base\application::run() @ line 17     121314151617          require(__dir__ . '/../config/main.php'),         require(__dir__ . '/../config/main-local.php')     );      $application = new yii\web\application($config);     $application->run(); 

i have encountered same error message. in case problem when turning on i18n means of yii::t. turned out gii somehow not add leading "\" when generating model template, namely public function attributelabels() method. changed

return [   'id' => \yii::t('app', 'id'),   'fullname' => \yii::t('app', 'full name'), ]; 

to

return [    'id' => \yii::t('app', 'id'),    'fullname' => \yii::t('app', 'full name'), ]; 

and error disappeared. try same.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -