Using gii gives syntax error

I’m using the basic template on Linux Mint 20 and am trying to get a CRUD working. I have been unable to get the database connection using the tutorial code - which is excellent upto this point, so have tried gii.

The CRUD generator gives me this output:
indent preformatted text by 4 spaces
Generating code using template “/var/www/html/basic/vendor/yiisoft/yii2-gii/src/generators/crud/default”…
generated controllers/CountryController.php
generated models/CountrySearch.php
generated views/country/_form.php
generated views/country/_search.php
generated views/country/create.php
skipped views/country/index.php
generated views/country/update.php
generated views/country/view.php
indent preformatted text by 4 spaces
but when I run : http://localhost/basic/web/index.php?r=country%2Findex

I get:

syntax error, unexpected end of file

in /var/www/html/basic/controllers/CountryController.php at line 43– yii\base\Controller::render()

which has this code:

public function actionIndex()
$searchModel = new CountrySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,

Any ideas what the generator is generating wrongly?


This is probably the reason

skipped views/country/index.php


Thanks for the reply.

I’ve gone through the tutorial steps again and still have the ‘skipped views’ message.

However, instead of the syntax error I now get:


You may change the content of this page by modifying the file /var/www/html/basic/views/country/index.php .

which is what this file contains. So at least the page is showing.

I guess the question is why the view, or enough of the view code, is not being created - I am using the suggested path - @app/views/country - in the View Path.

Is there something else I’m missing? There doesn’t seem to be a separate View generator.



Hi @Philb,

I guess you had used the Controller Generator before you tried the CRUD generator, and you already had index view.
So you have to replace it by setting the overwrite checkbox when you generate the CRUD files.

Hi softark,

Absolutely right! I get the idea now - something left over from a previous effort - possibly pre-gii.

View now showing data.

Many thanks