G
G
Gleb Vas2018-05-08 22:25:59
Yii
Gleb Vas, 2018-05-08 22:25:59

How to setup CNC GET parameter on YII2?

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false, 
            'rules' => [
                '?<key>=<value>' => '/<key>/<value>'
            ],
        ],

here is my component with urls.
Links look like:
basic/shop/products?id_category=7
I want to see it like this:
basic/shop/products/id_category/7
can you tell me how to do it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dave Hornigan, 2018-05-09
@DeyvHorni

'rules' => [
    'shop/products/<id_category:\d+>' => 'shop/products'
],

with such a rule, the link will be: basic/shop/products/7
or
'rules' => [
    'shop/products/id_category/<id_category:\d+>' => 'shop/products'
],

then it will be as you want

A
Artem Spiridonov, 2018-05-08
@customtema

Routing.

V
Viktor Yanyshev, 2018-05-09
@villiwalla

If you pass GET parameters in the url, then they need to be represented a little differently in the array index, for example:

'/news/<category_id:[\d]+>/<article_id:[\d]+>' => 'news/show'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question