【发布时间】:2013-02-24 16:07:13
【问题描述】:
我在 CakePHP 1.3 中与 Categories -> Products 有简单的模型关系
CategoryhasMany 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
)
)
)
)
【问题讨论】:
标签: cakephp model cakephp-1.3