简体   繁体   English

在Yii 1.1.17中制作自定义网址

[英]Making Custom Url in Yii 1.1.17

I am facing a problem in making custom URL using Yii framework. 我在使用Yii框架制作自定义URL时遇到问题。 I need to make custom URL in the format like "category/product". 我需要以“类别/产品”之类的格式制作自定义网址。

The category URL slug and product URL slug comes from the database. 类别URL段和产品URL段来自数据库。

Which rule should I implement to make it happen. 我应该实施哪个规则才能实现这一目标。 I am pretty confused about it. 我对此很困惑。

I have the applied the rule mentioned like that 我已经应用了这样提到的规则

'<info:([\w-]+)>'=>'main/generic/index'

Where info is the parameter and it makes the URL perfect like this 其中info是参数,它使URL像这样完美

www.abc.com/xyz.html

where xyz can be a category or product. 其中xyz可以是类别或产品。 Now what i want is the 'category/product'. 现在我想要的是“类别/产品”。

Kindly help. 请帮助。

Thanks 谢谢

'category/<url:.+>' => 'category/product',

产品函数具有参数的地方

'category/<slug:.+>' => 'category/product',

And your product function will be 您的产品功能将是

function actionProduct($slug){

}

Try this. 尝试这个。 It works for me. 这个对我有用。

'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',

Then your URL will "category/product" where controller is categoryController.php and action is actionProduct(). 然后,您的URL将为“类别/产品”,其中控制器为categoryController.php,操作为actionProduct()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM