我在 CakePHP 1.3 中与 Categories -> Products 有简单的模型关系
Category
有很多Products
我在不同控制器中获得的数据数组之间存在细微差别。数据在控制器Product
中作为关联模型获取时在主产品数组中,在获取Categories
时是分开的Products
。
例如获取“Product1”
在Categories
- $category['Product'][0]['title']
并且在Products
- $product[0]['Product']['title']
我想使用相同的元素来展示产品。将使用哪种数组方案只是为了相同并不重要。进行修改的正确位置在哪里?我可以在获得这些数组后对其进行修改,但不要认为这是最好的选择。
当我在Categories
控制器中并获得一个类别时,我得到了这个:
// $this->Category->findById('12');
Array
(
[ProductCategory] => Array
(
[id] => 12
[title] => Category 1
[updated] => 2013-02-24 10:06:15
[created] => 2013-02-24 10:06:15
)
[Product] => Array
(
[0] => Array
(
[id] => 4
[parent_id] => 12
[title] => Product1
[updated] => 2013-02-24 10:17:01
[created] => 2013-02-24 09:12:59
)
[1] => Array
(
[id] => 6
[parent_id] => 12
[title] => Product2
[updated] => 2013-02-24 10:16:54
[created] => 2013-02-24 09:13:53
)
)
将所有产品放入Products
控制器时:
// $this->Product->find('all');
Array
(
[0] => Array
(
[Product] => Array
(
[id] => 10
[parent_id] => 12
[title] => Product1
[updated] => 2013-02-24 10:16:42
[created] => 2013-02-24 09:16:35
)
)
[1] => Array
(
[Product] => Array
(
[id] => 8
[parent_id] => 12
[title] => Product2
[updated] => 2013-02-24 10:16:47
[created] => 2013-02-24 09:15:39
)
)
)
)