我遇到了URL规则互相覆盖的问题。 的URL约定,我需要在我的项目如下:Yii url规则覆盖彼此
test.com/Products/Decorations/ //for Catalog listings in that Category
test.com/Products/Decorations/Winter-Decorations/8 //for Product listings in that Catalog
test.com/Products/Decorations/8/christmas-tree-bell.html //for viewing exact products
我不是一个Yii的URL管理专家,我知道有一百万更好的方法可以做到这一点,但我重写规则如下:
'/<rootCategory>/<categoryName>/<id>' => 'catalogs/index',
'/<rootCategory>/<categoryName>/<catalogTitle>/<id>' => 'products/index',
'/<rootCategory>/<categoryName>/<id>/<url_slug>' => 'products/view',
现在发生了什么,当规则按照这个顺序时,查看产品的规则不起作用。我得到一个错误:
500 Trying to get property of non-object.
但是当我移动最后一个规则一个,就像这样:
'/<rootCategory>/<categoryName>/<id>' => 'catalogs/index',
'/<rootCategory>/<categoryName>/<id>/<url_slug>' => 'products/view',
'/<rootCategory>/<categoryName>/<catalogTitle>/<id>' => 'products/index',
上市的所有产品在目录中的规则不起作用抛出同样的错误消息,但是查看产品的规则起作用。
非常感谢您的帮助。
非常感谢你,添加正则表达式的id帮助。我知道是什么导致了这个错误,但不知道为什么这些规则搞乱了。从来不太了解正则表达式。 –