Yii Framework Forum: URL Routing - unable to match specific GET param? - Yii Framework Forum

Jump to content

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

URL Routing - unable to match specific GET param? Rate Topic: -----

#1 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 25 April 2010 - 11:23 PM

When creating rules for a route, it appears there is no way to say that:
array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),


should be matched *exactly*.

I can write rules for /site/page with no problem, but capturing the fact that "view" value must equal "about" appears to not be possible?

The only alternative I've found is to write a full path URL, such as:
array('label'=>'About', 'url'=>'/site/page/view/about'),


Which would then be matched by:
'<_v:\w+>'=>'site/page/view/<_v>',


But strangely enough, is not matched by:
'<view:\w+>'=>'site/page',



This means that, a full hard-coded path route can be matched by regex expecting a hard-coded path.
But you can't match a parameterized route using a path format.
And you can't match a path format route using a parameterized format.
And you can't match an explicit parameterized route with a specific value.

Correct?



I tend to be unclear, if that is the case here, let me know...
Need live Yii support? - Join the #yii IRC channel on Freenode!
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 26 April 2010 - 02:47 AM

View Postintel352, on 25 April 2010 - 11:23 PM, said:

I tend to be unclear, if that is the case here, let me know...


A little. ;)

So you have a rule with parameters. If one of these parameters has a specific value, another rule should match, right? You can try this:

array(
  'some/other/url/<view:about>'=>'site/page',
  '<view:\w+>'=>'site/page',
)

0

#3 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 26 April 2010 - 10:13 AM

View PostMike, on 26 April 2010 - 02:47 AM, said:

A little. ;)

So you have a rule with parameters. If one of these parameters has a specific value, another rule should match, right? You can try this:

array(
  'some/other/url/<view:about>'=>'site/page',
  '<view:\w+>'=>'site/page',
)



Thanks Mike, I appear to have missed that.
What about if you want an empty route? (i.e. - site index should match /site/page/view/whatever)
In that situation, there doesn't seem to be any way to match, without having the result show up in the route, correct?
Need live Yii support? - Join the #yii IRC channel on Freenode!
0

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 26 April 2010 - 10:46 AM

Again not sure if i understand. You mean something like this?

array(
  'some/page/view/whatever'=>'site/index',
)

0

#5 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 26 April 2010 - 10:50 AM

Something like this:
array(
    ''=>'site/page/view/whatever',
)


So that the website's index will map to "site/page/view/whatever", and links to that file won't mention the file path.

So it would always be:
http://www.mysite.com/


Instead of:
http://www.mysite.com/site/page/view/whatever

Need live Yii support? - Join the #yii IRC channel on Freenode!
0

#6 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 26 April 2010 - 11:29 AM

I'm confused now :)

array(
    ''=>'site/page/view/whatever',
)


The right side is not a route...
0

#7 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 26 April 2010 - 11:40 AM

To clarify:

array(
    ''=>'site/page/view/whatever',
)


The above will match a URL created in Yii that matches that exact format. The URL itself is a Yii PATH-format URL, though when using the command to create a URL, Yii probably sees it as a complete URL instead of a route.


What I should have asked was, a Yii URL that creates:
site/page/view/whatever


Would look like this when passed to $this->createUrl():
array('site/page', array('view'=>'whatever'))



So how can I match that specifically as a route rule, so that it acts as the index page?
Currently I've had to resort to creating the URL in Yii using the PATH format, but to maintain consistency, I'd much rather use the route/params style.


I guess what I'm looking for is the ability to turn this:
array(
    ''=>'site/page/view/whatever',
)


into this:
array(
    ''=>array('site/page', 'params'=>array('view'=>'whatever')),
)

Need live Yii support? - Join the #yii IRC channel on Freenode!
0

#8 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 26 April 2010 - 03:24 PM

Maybe it's easier if you supply a list of different arguments for creatUrl() and what URLs you'd like to be created. Actually i still don't really understand what you try to do...
0

#9 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 26 April 2010 - 04:15 PM

I'm not sure, but is this what you want?
0

#10 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 26 April 2010 - 04:19 PM

View PostY!!, on 26 April 2010 - 04:15 PM, said:

I'm not sure, but is this what you want?


Nice find Y!!, that would likely work. I'll star that ticket so I'm notified when it's solved, thanks!
Need live Yii support? - Join the #yii IRC channel on Freenode!
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