I have 2 modules in my applications: admin and customer.
My goal is to use SEO friendly URL to call all the views of my application.
For example: /customer/restaurant/view/34/My+Shop
If I use this simple code in all my webpages it works fine:
CController::createUrl(‘customer/restaurant/view’,array(‘id’=>$this->id,‘title’=>$this->title));
but unfortunately in all my web pages I have this code
Controller::createUrl(‘restaurant/view’,array(‘id’=>$this->id,‘title’=>$this->title));
Actually my URL MANAGER settings are the following:
'urlManager'=>array(
'urlFormat'=>'path',
//'showScriptName'=>true,
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<action:\w+>/<id:\d+>/<title:.*?>' => '<controller>/<action>',
),
Can you please help me to understand how to set URL MANAGER??
something like
‘/customer/restaurant/view/<id:\d+>/<title:\w+>’ => ‘restaurant/view’
public function actionView($id, $title)
{
…
}
I’ve tried to add your rule to my URL MANAGER
‘urlManager’=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'/customer/restaurant/view/<id:\d+>/<title:\w+>' => 'restaurant/view',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),
The address is displayed corretly (//localhost/myapp/customer/restaurant/view/34/My+Shop) on the source page, but once I click on the link there is a problem on the destination page: "404 error: Page not found"
Thanks.
argent
(Argent Hun)
5
regular-expressions.info/shorthand.html:
Try this (I added the space char to the character class):
'/customer/restaurant/view/<id:\d+>/<title:[\w ]+>' => 'restaurant/view',
Dear all,
I found the solution.
It was a double problem:
-
routing the requests to customer module
-
decoding SEO friendly url
These are my settings for URL MANAGER.
//ROUTING LINE
‘restaurant/<action>/*’ => ‘customer/restaurant/<action>’,
//DECODING SEO FRIENDLY URL
‘<controller:\w+>/<action:\w+>/<title:.*?>’ => ‘<controller>/<action>’,
‘<controller:\w+>/<action:\w+>’ => ‘<controller>/<action>’,
Thank you all for your help.