Error when playing with

When i try to run the country script that I (or gii) created in The definitive guide/Getting started/Generating Code with gii, I get the following error:

PHP Parse Error – yii\base\ErrorException

syntax error, unexpected ‘namespace’ (T_NAMESPACE)

  1. in C:\xampp\htdocs\basic\controllers\CountryController.php

I enter "basic/web/index.php/country/index" in my browser.

"basic/web/index.php/country" gives the same error.



Simple issue.

The namespace in these files is wrong or not set.

According to what you have posted…

In file \basic\controllers\CountryController.php add at directly at the top:


namespace app\controllers; 


Thanks, but that line is already there.

btw, the following variables might be of interest:

‘DOCUMENT_ROOT’ => ‘C:/xampp/htdocs’,

'REQUEST_SCHEME' =&gt; 'http',

'CONTEXT_PREFIX' =&gt; '',

'CONTEXT_DOCUMENT_ROOT' =&gt; 'C:/xampp/htdocs',

'SERVER_ADMIN' =&gt; 'postmaster@localhost',

'SCRIPT_FILENAME' =&gt; 'C:/xampp/htdocs/basic/web/index.php',

'REMOTE_PORT' =&gt; '57555',




'QUERY_STRING' =&gt; '',

'REQUEST_URI' =&gt; '/basic/web/index.php/country/index',

'SCRIPT_NAME' =&gt; '/basic/web/index.php',

'PATH_INFO' =&gt; '/country/index',

'PATH_TRANSLATED' =&gt; 'C:&#092;&#092;xampp&#092;&#092;htdocs&#092;&#092;country&#092;&#092;index',

'PHP_SELF' =&gt; '/basic/web/index.php/country/index',

Should have read your answer better, especially "directly at the top"

I found the letter r outside my comments above the namespace row.

Many thanks!