Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
761 views
in Technique[技术] by (71.8m points)

routes - Yii2 Conditional Url routing

I want to change the Url. This is what I have used but its not working in second case.It gives me 404

Case 1:  user/view?id=35
[
    'pattern' => 'view-user-<id>',
    'route' => 'user/view',
    'suffix' => '.php',
],
Case 1 result: view-user-35.php

Case 2: user/view?id=35&tab=4
[
    'pattern' =>'view-user-<id>-<tab>',
    'route' => 'view-user-<id>.php',
    'suffix' => '.php',
],
Case 2 result: view-user-35.php?tab=4

but after refreshing the page it says 404 page not found. 
Case 2 expected result : view-user-35-4.php.

Here tab="any number" is conditional. It can there or it can not be there.

Note: tab is appended by using javascript.

question from:https://stackoverflow.com/questions/65840024/yii2-conditional-url-routing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is the solution for this question this is what I tried for now and working for me.

 [
   'pattern' =>'view-user-<id>-<tab>',
   'route' => 'view-user-<id>.php',
   'suffix' => '.php',
   'defaults' => array('tab' => '')
 ],

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...