我有一个模型订单。
当我在我的表Order中执行find('all')
时,cakephp会返回如下数据:
array(
(int) 0 => array(
'Order' => array(
'id' => '10'
)
),
(int) 1 => array(
'Order' => array(
'id' => '11'
)
)
)
有没有办法将'Order'重命名为'myTEST'?
答案 0 :(得分:1)
在Order
模型中,您可以实施afterFind
回调,将[Order]
替换为[myTEST]
。这样的事可能适合你:
public function afterFind($results, $primary = false) {
$new_results = array();
foreach ($results as $key => $val) {
foreach($val as $v){
$new_results[$key]['myTEST'] = $v;
}
}
return $new_results;
// OR you could also take this approach - Less coding and perhaps more efficient
// foreach ($results as $key => $val){
// $results[$key]['myTEST'] = $results[$key]['Order'];
// unset($results[$key]['Order']);
// }
// return $results;
}
我根本没有测试过这个。