routes ... again

hi all,

ok I think I  am missing something

the guide states

Quote

The rules are specified as an array of pattern-route pairs, each corresponding to a single rule. The pattern of a rule must be a valid regular exp​ression without delimiters and modifiers. It is used to match the path info part of URLs. And the route should refer to a valid controller route.

so I understand I can specify a regex in the pattern part of a rule and if my request matches this pattern the route part of the rule will be used as route.

but

in my app I have a rule like this :

'[a-z]+' => 'site/index'

which translates internally into /^[a-z]$/

which should match a request like

/myrequest

which should use 'site/index' as route

I debugged a little (followed the request) and there is is this part in CurlManager :

that I don't understand

thanks for any help on this

First, you are not reporting any problem in this problem, right?

The line of the code is to preclude most of the URL rules based on the current pathinfo and the signature of each rule. This is mainly for performance improvement. You can ignore this line in the first read.

hi Qiang,

thanks for the reply

sorry about not stating my problem accurately

I mean I would expect a request like this :

www.mysite.com/myrequest

to use the 'site/index' route

which fails (page not found error)

in the end what I  am trying to achieve is to be able to have slugs first thing after my host_info part in the url

http://www.mysite.com/this-is-a-post

would redirect to

http://www.mysite.co…=this-is-a-post

How can I achieve this ?

thanks a lot

Did you set your .htaccess so that index.php can be hidden?

yes

what i'd like to able to do is to have any regex in the pattern part of a route to match a route

I think I am looking for something like this

'([\w-]+)' => 'post/read/$1'

where $1 is the captured part of the regex

I think Yii does not allow this for now (or does it ?) but is there a yii way ?

hope I explain well enough

I think ‘<post:[a-z]+>’=>‘post/read’ is what you need. You can access $_GET[‘post’] to retrieve the value.

indeed it is

thanks a lot

thought I tried that … :(

but do you agree that

'[a-z]+' => 'site/index'

or

'[a-z]+/read' => 'post/read'

won't work ?

It should work, although you can't get the information from the pathonfo.

well I just setup a test project with

  • .htaccess to deal with index.php

and I get a page not found if trying to access

testproject.local/anythingicanthinkof

I've attached the project

Maybe I don't undertand when you say :

Quote

It should work, although you can't get the information from the pathinfo.

thanks for your patience

What is the exact error message? Are you sure your .htaccess is correct?

the request :

http://www.testyiiro…cal/thisisatest

the error :

Page Not Found

Unable to resolve the request "thisisatest".

the .htaccess

am I  doing something wrong ?

ah, my bad. This won't work because regexp can only appear in <>.

ah this makes it clearer to me :)

I guess as a follow up to the controller/action placeholders maybe it would be a nice addition (if this is doable) to be able to do this, and maybe to have the possibility to use regex subexp​ressions to be replaced in the route

like

'(['a-z']+)/<id:\d+>' => '$1/read' //reach any controller read action

or

'admin/(['a-z']+)/' => 'admin/$1/admin' //reach any admin module controller admin action

don't know if this makes sense

anyway

I thought the guide was a bit misleading in the sense that it says that a pattern is a regex

thanks for your time !

Quote

ah this makes it clearer to me :)

I guess as a follow up to the controller/action placeholders maybe it would be a nice addition (if this is doable) to be able to do this, and maybe to have the possibility to use regex subexp​ressions to be replaced in the route

like

'(['a-z']+)/<id:\d+>' => '$1/read' //reach any controller read action

or

'admin/(['a-z']+)/' => 'admin/$1/admin' //reach any admin module controller admin action

don't know if this makes sense

anyway

I thought the guide was a bit misleading in the sense that it says that a pattern is a regex

thanks for your time !

I'm looking for exactly this functionallity. Something like this:

'<location:.>/<controller:.>/<action:.*>' => "$2/$3"

Would be great if this works!!!