[symfony-users] Re: Routing rules where the parameter to be set is not exactly what should appear in the URL

2009-02-14 Thread Tom Boutell

Hi Bernhard,

Thanks for responding. You suggested:

test_index:
  url:  /test
  param: { module: test, action: index }
test_images:
 url:   /test/images
 param: { module: test, action: index, type: image }

With that first rule in place, I would get the following results:

test/index?type=image   =>   /test?type=image
test/index?type=video=>   /test?type=video
test/index  =>  /test

In other words, the first rule would match all requests for the
test/index action and no further rules would be evaluated. Symfony
routing rule matching isn't a "find the best fit" system. It's a "find
the first fit" system.

If you put the rules in the opposite order, then the images rule would
match every request for test/index and force type to image for all of
them, which would be incorrect.

Allow me to restate what I really want:

test/index?type=image   -->   /test/images
test/index?type=video   -->   /test/videos
test/index   -->  /test

Even if we turn off the extra_parameters_as_query_string option for
the test/index rule so it doesn't match everything, we still hit the
wall trying to get the images and photos rules to differentiate based
on something in the URL rather than the first one simply overriding
the other.

So far it looks like :type is the only way to go. I could get what I
want by converting plural :type values back and forth to singular
myself rather than trying to get routing rules to do it automatically
for me.

-- 
Tom Boutell

www.punkave.com
www.boutell.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: Routing rules where the parameter to be set is not exactly what should appear in the URL

2009-02-14 Thread Bernhard Schussek

Hi Tom,

It may be a silly suggestion, but why don't you just add the /test rule?

test_index:
  url:  /test
  param: { module: test, action: index }
test_images:
 url:   /test/images
 param: { module: test, action: index, type: image }

On Fri, Feb 13, 2009 at 7:47 PM, Tom Haskins-Vaughan
 wrote:
> I may be completely off track here, but does the requirements field not
> use regular expressions? If it does, is there not something you can do
> like this:
>
>   requirements: { type: (image|video)s }

Even if you do this, your parameter "type" will still contain either
"images" or "videos". Remember that requirements are used just for
asserting the parameter correctness, not for transforming it.


Bernhard

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: Routing rules where the parameter to be set is not exactly what should appear in the URL

2009-02-13 Thread Tom Haskins-Vaughan

I may be completely off track here, but does the requirements field not 
use regular expressions? If it does, is there not something you can do 
like this:

   requirements: { type: (image|video)s }


Tom Boutell wrote:
> I spent some time puzzling over these two routing rules today:
> 
> 
> images:
>   url:   /test/images
>   param: { module: test, action: index, type: image }
> 
> default_index:
>   url:   /:module
>   param: { action: index }
> 
> I had thought that calling link_to on this URL:
> 
> test/index
> 
> Would generate this:
> 
> /test
> 
> But it didn't. It generated /test/images.
> 
> Eventually I read the fine manual and learned that parameters
> explicitly set in the way I have set type: here:
> 
> images:
>   url:   /test/images
>   param: { module: test, action: index, type: image }
> 
> Are defaults, NOT things to be looked for and matched in the internal URI. 
> Okay.
> 
> So I rewrote my rule this way:
> 
> test_types:
>   url:   /test/:type
>   param: { module: test, action: index }
>   requirements: { type: (image|video) }
> 
> And indeed that works. It matches only when the second URL component
> is image or video, and lets other rules succeed otherwise. That's
> progress.
> 
> However, I want the plural form in the URL rather than the singular.
> That is, I want:
> 
> test/index?type=video
> 
> To map to:
> 
> /test/videos
> 
> This would work if params set in the param: array were matched against
> the internal URI. Alas, by design, they are not.
> 
> Is there a way to get the behavior I want with a pattern routing rule?
> 
> Thanks!
> 

-- 
Tom Haskins-Vaughan
Temple Street Media: Design and Development for the Web
t...@templestreetmedia.com | www.templestreetmedia.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---