Reputation: 55
Hi I am having trouble in URl management in yii.
I have a Model Vendor and another Model Products. There is an action Info in both of the controllers. Now I want to create my URL as
www.example.com/abc.html instead of www.example.com/vendor/info/v-name/abc.html www.example.com/xyz.html instead of www.example.com/product/info/p-name/xyz.html
v-name and p-name are the parameters.
I have written the rewrite rule as
'<v-name:\w+>'=>'vendor/info',
'<p-name:\w+>'=>'product/info',
But that doesn't seem to work. As the first rule is applied in product case also and in the end the exception is thrown. What should be done?
Thanks alot for the help.
Upvotes: 1
Views: 70
Reputation: 43549
Currently your both links means check if url contains word
. So http://example.com/example
will have no information if it's product or vendor. Since your vendor rule stands above product so every url is matching first rule and not executing further. You need to add any "marker" to know if it's vendor or product.
'vendor\/<v-name:\w+>' => 'vendor/info',
'product\/<p-name:\w+>' => 'product/info',
but yes, your url will change. You can still change url to something like <v-name:\w+>\/v
and url will look like http://www.example.com/some name of your vendor here/v
Upvotes: 1
Reputation: 864
I'd recommend you to use a more generic rule:
'<controller:\w+>/<action:\w+>/name/<name:\w+>' => '<controller>/<action>'
name attribute will be available in your actions:
public function actionInfo() {
$name = Yii::app()->request->getParam( 'name', 'defaultValue' );
}
Upvotes: 1