Generating Tutorial CRUD Code doesn't work

Hey Guys,

because my work with Yii is my very first experience regarding php I started working through the tutorial given in the guide 2.0. Until now everything worked out very fine, but now I have Problems generating the CRUD code.

The first thing I noticed is, that the code generation doesn’t even work when I follow this picture and insert @app\views\country for View Path. When I leave out the ‘@’ it suddenly works…

But when I try to access the index page after successfully genrating the code I get another error:

 PHP Notice – yii\base\ErrorException

Undefined variable: countries

    1. in /home/blabla/views/country/index.php at line 7



    use yii\helpers\Html;

    use yii\widgets\LinkPager;




    <?php foreach ($countries as $country): ?>


            <?= Html::encode("{$country->name} ({$country->code})") ?>:

            <?= $country->population ?>


    <?php endforeach; ?>



    <?= LinkPager::widget(['pagination' => $pagination]) ?>

Line 7 means the head of the foreach-loop.

I hope you can help me, thanks :)


did you resolved it.

i’m begginer and i have same bug.

i hope you can help me.


Should be "@app/views/country" instead of "@app\views\country".

Assuming you took tri’s advice and generated CRUD with the views input changed to @app/views/country? It appears that in your controller’s public function actionIndex() there is no $countries variable being sent to the view when it is rendered.

Inside of the actionIndex() function in your countryController there should be some code like this:

return $this->render('index', [

	'countries' => $countries,


That will render the views/country/index.php view file and send the $countries array so that it can be accessed in your view file.

If you share your controller’s actionIndex code, I can likely help more.