Routes with arbitrary number of params

Hi all.

I’m trying to build some kind of catalog and I want URLs like this:




I wrote some rules, like this:

<category:[\w\/]+>' => 'catalog/index'

Works good in "direct" way.

But when I’m trying to reverse

CHtml::normalizeUrl((array('catalog/index', 'category' => 'test/test2'))

I get encoded URL: /test%2Ftest2

How can I avoid this?

It is being encoded because you’re indeed passing a slash inside a parameter value.

You could define a rule for each category-set:

<category1:[\w\/]+>/<category:2[\w\/]+>/<category:3[\w\/]+>' => 'catalog/index'

<category1:[\w\/]+>/<category:2[\w\/]+> => 'catalog/index'

<category1:[\w\/]+> => 'catalog/index'

With the upcoming 1.1.8 release you could make use of a custom url rule class. Read here for details.

The question is how to pass a slash and avoid escaping :)

Yes, but I was talking about (almost) unlimited tree depth.

Thanks, I’ll check it out.

@Angel your post helped me answered my questions here

And now I am having the same passing slash problem as you…

Are there any way to do this without waiting for 1.1.8?

Yes! I found out how to pass slashes without encoded with the help of dburlmanager. Its the next best thing before 1.1.8 arrival

See my post

Yii 1.1.8 is here already!