我有一个名为类别的表:
- ID
- 分类名称
- parent_id
和表产品:
- ID
- 类别ID
- 产品名称
为了简单起见,product_name 和 catogory_name 是唯一的 URL 别名
我想像那里一样制作网址
shop/computer_parts/cpu/intel - 是具有父 cpu 和计算机的“intel”类别的 url
和产品喜欢
shop/computer_parts/cpu/intel/intel_core_i5_2500k - 是产品
我看到了解决方案,添加了模型方法,例如
类别型号
public function geturl() {
***in cycle getting aliases of all parents***
return Yii::app()->createUrl( ...etc
}
和产品
public function geturl() {
*** getting aliases of category and parents ***
return Yii::app()->createUrl( ...etc
}
这样做更简单吗?