K
K
Kekoc2015-01-18 16:33:15
Yii
Kekoc, 2015-01-18 16:33:15

Human friendly url, how to use urlmanager in yii2 correctly?

Hello. Already 100500 topic but I can't get the result.
There is a project on yii2 (trial, I'm learning new tools for myself), in addition to the standard controller, there is CountryController. It can be accessed using the link ----> localhost/yii-basic-app-2.0.1/basic/web/?r=country
By inserting urlmanager into the components area in the config, I try to access the following link - --> localhost/yii-basic-app-2.0.1/basic/web/country but the object was not found.
This is what urlmanager looks like

'urlManager' => [
            'enablePrettyUrl' => true,
            'rules' => [
                '/country'=>'country/index'
            ],
            // ...
        ],

Those. if I understand correctly, first of all we write what kind of url we need to process, second we set this url to a controller and its action, in this case, the CountryController controller and its index function (but you can not specify, by default it seems like always index).
Just in case, the .htaccess file
Options +FollowSymLinks
IndexIgnore */*
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
PS In symfony2, it seemed to me much easier with this case, because would simply indicate before the function an annotation to this url.
Help others!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Shurman, 2015-01-23
@VaShu

'urlManager' => [
    'enablePrettyUrl' => true,       
    'showScriptName' => false,
    'enableStrictParsing' => false,
        'rules' => [
            '/country'=>'country/index',
            ],
        ],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question