S
S
s4nity2016-10-08 20:00:21
Yii
s4nity, 2016-10-08 20:00:21

How to make beautiful links in yii2 framework?

Welcome all!
Started learning yii2 and ran into a link problem. By this variant /site/view/?id=AU $_GET["id"] I can get, but how can I get $_GET["id"] also by this variant /site/view/AU and pass it to the controller? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-10-10
@s4nity

[
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
 '/' => 'site/index',
'/site/view/<id>' => 'site/view',
            ],
        ],
    ],
]

in site controller
public function actionView($id){
echo $id;
}

now query /site/view/AU will output AU

K
Kirill Arutyunov, 2016-10-08
@arutyunov

urlManager must be configured in the config.
Everything is in the documentation. Or have you not looked?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question