D
D
Dmitry2020-08-28 14:55:36
Yii
Dmitry, 2020-08-28 14:55:36

Why can't the controller find the "index" view?

Please tell me how is it right?
Everything is as in the "manual" - in the Controllers folder I created StatisticController.php in which I created an instance of the class:

<?php

class StatisticController extends Controller
{
    public function actionIndex()
    {
        $this->render('index');
    }
}


and in the view directory, I created a statistic folder with the index.php file with the following content:
<h1>TEST</h1>

As a result, it throws a CException (see below):
The StatisticController controller cannot find the "index" view.

/var/www/html/protected/vendors/yii/web/CController.php(881)
{
870         if(($viewFile=$this->getViewFile($view))!==false)
871         {
872             $output=$this->renderFile($viewFile,$data,true);
873             if($processOutput)
874                 $output=$this->processOutput($output);
875             if($return)
876                 return $output;
877             else
878                 echo $output;
879         }
880         else
881             throw new CException(Yii::t('yii','{controller} cannot find the requested view "{view}".',
882                 array('{controller}'=>get_class($this), '{view}'=>$view)));
883     }


stack trace
#1	
–  /var/www/html/protected/controllers/StatisticController.php(7): CController->render("index")
2 
3 class StatisticController extends Controller
4 {
5     public function actionIndex()
6     {
7         $this->render('index');
8     }
9 }

#9	
–  /var/www/html/index.php(39): CApplication->run()
34     ini_set('display_errors', 'Off');
35     error_reporting(0);
36 }
37 
38 require_once($yii);
39 Yii::createWebApplication($config)->run();
40 
41 //echo phpinfo();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
danya2000, 2021-08-30
@danya2000

Try this

<?php
class StatisticController extends Controller
{
    public function actionIndex()
    {
        $this->render('/statistic/index');
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question