Yii Framework Forum: How to exclude full index path from the routes - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to exclude full index path from the routes

#1 User is offline   koredalin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 23-September 17

Posted 12 May 2018 - 04:00 AM

Hello All,
I have made a post in Facebook: "Yii2 PHP framework" group "/yii2talk/permalink/2037978059776059/".
I understood that it's place is here, by the moderator announcement. So, I ask you here too. If needed - I'll remove the post in Facebook.

I have read many tutorials, but I cannot find one routing configuration.
I have a question about the routes in Yii2.
I'm interested in how to disable the "<controller>/index" pattern from the below passage, but keep only "<controller>" pointing to "<controller>/index".
Please, advise me.
File: "/config/web.php".

'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'rules' => [
'<controller>' => '<controller>/index',
'<controller>/<action>' => '<controller>/<action>',
],
],

I don't like the idea to make exceptions in the controllers, because I have to make some in any controller.
Thank you, all!
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,647
  • Joined: 16-February 11
  • Location:Japan

Posted 16 May 2018 - 09:19 AM

Hi koredalin, welcome to the forum!

View Postkoredalin, on 12 May 2018 - 04:00 AM, said:

File: "/config/web.php".
'urlManager' => [
	'enablePrettyUrl' => true,
	'enableStrictParsing' => true,
	'rules' => [
		'<controller>' => '<controller>/index',
		'<controller>/<action>' => '<controller>/<action>',
	],
],



The rules should be something like the following:
    'rules' => [
        '<controller:\w+>' => '<controller>/index',
        '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
     ],

Note that the keys in the array of rules are the url patterns, and the values the routes.

https://www.yiiframe...uting#url-rules
0

#3 User is offline   koredalin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 23-September 17

Posted 22 May 2018 - 07:31 AM

View Postsoftark, on 16 May 2018 - 09:19 AM, said:



Hi softark,
This is not, what I have looked for. I found my answer, but now I have issues with the main controller. I'll type here the result, when I'm done.
Meanwhile, can you please have a look at my next Yii forum question: https://www.yiiframe...__1#entry316741

Thank you
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users