在Yii 1.1.17中制作自定义网址

时间:2016-11-03 07:00:53

标签: php yii url-routing yii-url-manager

我在使用Yii框架制作自定义网址时遇到问题。我需要以“category / product”这样的格式制作自定义网址。

类别URL slug和产品URL slug来自数据库。

我应该实施哪条规则才能实现。我很困惑。

我已经应用了像那样提到的规则

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

其中info是参数,它使URL完美如此

www.abc.com/xyz.html

其中xyz可以是类别或产品。现在我想要的是'类别/产品'。

请帮助。

由于

3 个答案:

答案 0 :(得分:0)

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

产品功能有一个参数来获取slu

答案 1 :(得分:0)

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

您的产品功能将是

function actionProduct($slug){

}

答案 2 :(得分:0)

试试这个。这个对我有用。

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

然后您的网址将为&#34; category / product&#34;其中controller是categoryController.php,action是actionProduct()。