Yii Framework Forum: Recursive urlManager rules - Yii Framework Forum

Jump to content

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

Recursive urlManager rules Rate Topic: -----

#1 User is offline   Phillip 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 11-January 10

Posted 13 May 2010 - 10:55 AM

Hello,

I was wondering if there is a way to make urlManager rules recursive. What I want to happen is the user will click on the Projects option in the menu, which links to projects/. I have a rule that says to send projects/ to posts/project (commented out in code below), which should then forward to post/index with tag=project.

The problem comes when it converts projects/ to posts/project; it looks for a posts controller instead of looking in rules again.

I tried to add a rule that says to forward all projects/ requests to post/index with tag=project, which works, but when I use $this->createUrl('post/index') or $this->createUrl('post/'), it always produces a link to projects/.

I also tried moving the order, but that didn't do anything. Any suggestions?

...
'urlManager'=>array(
	'urlFormat'=>'path',
	'rules'=>array(
		'post/<id:\d+>/<title:.*?>'=>'post/view',
		'post/<id:\d+>'=>'post/view',
		'posts/<tag:.*?>'=>'post/index',
		'projects/'=>array('post/index', 'defaultParams'=>array('tag'=>'project')), // works $this->createUrl('post/index') or $this->createUrl('post/') produces link to projects/
		//'projects/'=>'posts/project', // doesn't work
		'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
	),
),
...

0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,425
  • Joined: 17-January 09
  • Location:Russia

Posted 13 May 2010 - 11:03 AM

Try:
'<tag:project>s/'=>array('post/index'),

Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   Phillip 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 11-January 10

Posted 13 May 2010 - 11:10 AM

View Postsamdark, on 13 May 2010 - 11:03 AM, said:

Try:
'<tag:project>s/'=>array('post/index'),



Very nice... works perfectly. Thanks!
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