Having a small url problem after Gii generation


I am not sure I understood the url structure of YII.

I have created a model, controller and CRUD views.

The controller is called:


Everything has been generated in the folders that are in the backend but when I try to call the url:


I have also tried this:


Nothing happens, I always thought that the controller would be first before the view in the url.

Am I correct?

Thank you.

Ok so my first mistake is the mod_rewrite, just noticed it had to be included int he advanced template.

Please tell me is this is ok. thanks.

I have added both in the backend/config/main.php and backend/config/local-main.php file the below code:

      'urlManager' => [

        'class' => 'yii\web\UrlManager',

        // Disable index.php

        'showScriptName' => false,

        // Disable r= routes

        'enablePrettyUrl' => true,

        'rules' => array(

                '<controller:\w+>/<id:\d+>' => '<controller>/view',

                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',



Then in the backend/web folder I added and .htaccess file with this:

RewriteEngine on

# If a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward it to index.php

RewriteRule . index.php

I tried to retype the url, still not working…

Try with page-layout in the url link to the controller

Using Gii Tool try to generate some other controller called Test.

Then try to call http://localhost/yii2/backend/test

Actually since I added the url manager code I receive this error:

Invalid Call – yii\base\InvalidCallException

Setting read-only property: yii\web\Application::urlManager

1. in C:\xampp\htdocs\yii2\vendor\yiisoft\yii2\base\Component.php at line 195

186187188189190191192193194195196197198199200201202203204            foreach ($this->_behaviors as $behavior) {

                if ($behavior->canSetProperty($name)) {

                    $behavior->$name = $value;






        if (method_exists($this, 'get' . $name)) {

            throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);

        } else {

            throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);





     * Checks if a property is set, i.e. defined and not null.

     * This method will check in the following order and act accordingly:

Ok Got it,

This happened because I had put the urlmanager outside the component.

One question for you please, with the advance template, to I need to put this code also in the

backend main-local.php

backend main.php

frontend main-local.php

frontend main.php

and add the htaccess in both the web directories of the front and back end?

Am I correct?

No - if you don’t plan on making the configuration different, then in ‘common/config/main’ is OK.

The ‘-local’ config files are for secret things, like passwords. And they are ignored by Git.

Put everything else in main.php.

Yes. ;)