Yii Framework Forum: routing urlManager for domain/username/action - Yii Framework Forum

Jump to content

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

routing urlManager for domain/username/action Rate Topic: -----

#1 User is offline   SystemicPlural 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 134
  • Joined: 12-April 10

Posted 16 July 2010 - 06:26 AM

Hi

I'm new to Yii. I'm liking what I see, but I have a problem.

I'm trying to create routes that have usernames as the first parameter.
I've worked out how to get the index to route to the login action of the user controller:
'<user:\w+>' => 'user/login'


But if I try to route to a specific action I get a 404. eg /myusername/myaction
'<user:\w+>/<action:\w+>' => 'user/<action>'


What am I doing wrong?
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 16 July 2010 - 07:15 AM

Please read this guide's section: http://www.yiiframew...terizing-routes
0

#3 User is offline   SystemicPlural 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 134
  • Joined: 12-April 10

Posted 16 July 2010 - 07:42 AM

View Postandy_s, on 16 July 2010 - 07:15 AM, said:

Please read this guide's section: http://www.yiiframew...terizing-routes


Hi Andy. I have read the guide. I can't see what I'm doing wrong.

with:
'<user:\w+>/<action:\w+>' => 'user/<action>'

I'm defining two parameters; user and action. Both can be any string containing letters, digits, and underscores, and are separated by a forward slash.

The route is for the user controller, using the action defined at the end of the pattern.

I can't see how it is fundamentally different from the default:
<controller:\w+>/<id:\d+>'=>'<controller>/view

0

#4 User is offline   SystemicPlural 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 134
  • Joined: 12-April 10

Posted 16 July 2010 - 08:38 AM

Solved it.

I had another route previous to this one that was catching it.

'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'

0

#5 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 16 July 2010 - 08:43 AM

Shouldn't it be:

'<user:\w+>/<_a>' => 'user/<_a>',

?
0

#6 User is offline   SystemicPlural 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 134
  • Joined: 12-April 10

Posted 16 July 2010 - 09:28 AM

Yes that works too. I didn't realise that you could miss out the regex if you just want to match everything.

This works as well:
'<user>/<action>' => 'user/<action>'

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