Y
Y
Yuri2015-07-28 09:28:16
Yii
Yuri, 2015-07-28 09:28:16

Yii2. How to specify your links in the routing rules?

Greetings!
It is necessary that a link like /show?month=02&year=2015 leads to action perform/affichesearch
UrlManager now looks like this:

'urlManager' => [
    'enablePrettyUrl' => true,
    //'enableStrictParsing' => true,
    'showScriptName' => false,
    //'suffix' => '.php',
    'rules' => [
        ''=> '/site/index',
       'actors'=> 'employees/actors',
       'show'=> 'perform/afficheindex',
       'show?month=<month>&year=<year>' => 'perform/affichesearch',
       '<_c>/<_a>'=> '<_c>/<_a>',
       '<controller:\index>' => '<controller>/index',
       '<controller:>' => '<controller>/index',
    ],
],

There is an action in the controller.
The link is created like this:
Url::toRoute(['affichesearch', 'month' => $num, 'year' => $l_year]);

When I try to follow the link site.local/show?month=02&year=2015 , I get to the action page from the rule 'show' => 'perform/afficheindex',
Can you tell me what is the reason that I am directed to afficheindex?
Changed the order of these two rules - nothing has changed.
If we remove the rule
'show?month=<month>&year=<year>' => 'perform/affichesearch',

then the link takes the form site.local/perform/affichesearch?month=02&year=2015 and when I click on it, I get to the page I need.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander N++, 2015-07-28
@sanchezzzhak

show?month=&year=
No need to specify enough to declare 2 parameters in the method
Redirects because you have the first show leading to 1 method and the second to another show.
Swap the conditions

'show?month=<month>&year=<year>' => 'perform/affichesearch',
 'show'=> 'perform/afficheindex',

In Yii, rules are given priority to whoever finds them first - that and slippers.
I would do the filtering in the same afficheindex method or change show to search for another url.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question