T
T
Tamara Lamova2021-07-28 07:50:27
Yii
Tamara Lamova, 2021-07-28 07:50:27

Why does Url::toRoute() with a parameter add a question mark?

We have Yii2 with this routing:

'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName'  => false,
        'enableStrictParsing'  => false,
        'rules'           => [
           …
          'p'=>'product/index',
          'p/<add:\w+>/<id:(\d|-)+>'=>'product/<add>',
          'p/<action:\w+>'=>'product/<action>',

          '<action>'=>'site/<action>',
        ],
      ],


Thus, links like https://site.url/p/add/25 lead to the form for adding a product to a category with ID 25
( ProductController controller, actionAdd method with $id = 25 argument).

This works great.

In the view code, I add a link to add a product, let 's say So for some reason, the link appears with a parameter behind a question mark: https://site.url/p/add?id=25 And it is necessary - https://site.url/p /add/25 How to do it right?

Url::toRoute(['product/add', 'id'=>$categoryId])





Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question