Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
776 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 Reply

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' => '')
 ],

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...