Invalid CUrlManager matching

Hello,

I have next rules for CUrlManager:


            'rules' => array(

1:                //'estate/viewQuickInfo/id/<id:\d+>' => array('estate/viewQuickInfo'),

2:                '<estateTypeUrlTitle>/<cityUrlTitle>/<title>/<id:\d+>' => array('estate/view'),

3:                'estate/<title>/<id:\d+>' => 'estate/view',

            ) 

As i understood second rule should manage only urls with estateTypeUrlTitle, cityUrlTitle params:


    <?php echo CHtml::link(

        $data->getCaption(), array(

            '/estate/view',

            'estateTypeUrlTitle' => $data->type->urlTitle,

            'cityUrlTitle' => $data->city->urlTitle,

            'id' => $data->id,

            'title' => $data->urlTitle,

        ), array('class' => 'location'));

    ?>



but current rules also manage any link with id. For example:

http://heat.in/estate/viewQuickInfo/id/305

http://heat.in/estate/delete/id/305

http://heat.in/anycontroller/anyaction/id/305 !!!!!!!!!!

show same page, like http://heat.in/estate/view/id/305.

Then i uncomment rule 1 i have valid result for

http://heat.in/estate/viewQuickInfo/id/305 link, but i think it is invalid to add rule for each other controllers/action just so they will retain work?

Is it possible to do so second rule works only for URLs with estateTypeUrlTitle, cityUrlTitle params?

Konstantin

Hi slyder,

in you have this rule:




'<estateTypeUrlTitle>/<cityUrlTitle>/<title>/<id:\d+>' => array('estate/view'),



and url like:

site.com/string1/string2/string3/someINT

This means, that always controller Estate and action View will be requested.

If you just need to call controller/action/id/5, you don’t need rules.

Just set urlFormat to path, showScriptName to false and CUrlManager will do the rest.

site.com/estate/delete/id/5

Will call controller Estate, action Delete with get parameter ID = 5.

For this kind of URLs, rules are not needed.

If you want some custom URLs, like:

site.com/contacts

so then you need this rule:




'contacts' => 'site/contact', //controller Site, action Contact



And


CHtml::link('Contacts', array('site/contacts'));

or another example:




'contacts/<title>' => 'site/contact', //controller Site, action Contact



and




CHtml::link('Contacts', array('site/contacts', 'title' => 'Sales'));



This will output:

site.com/contacts/Sales

And in controller site, action contacts you will know, that contact form should be for Sales team ($_GET[‘title’] == ‘Sales’)…