【发布时间】:2015-04-11 05:43:12
【问题描述】:
afterFind() 的问题。
当前代码:
<?php
public function afterFind($results, $primary = false)
{
foreach ($results as $key => $val)
{
if (isset($val['User']['country_code']) && isset($val['User']['mobile']))
{
$results[$key]['User']['mobile'] = trim($val['User']['country_code']).trim($val['User']['mobile']);
}
}
return $results;
}
?>
它适用于$this->User->find(),但不适用于其他模型。
我有 3 个模型。 Room、Place 和 User。
<?php
$this->Place->bindModel(array('belongsTo' => array('User')));
$this->Room->bindModel(array('belongsTo' => array('Place')));
?>
当我尝试查找Room 数据时:
<?php
$data = $this->Room->find('first');
array(
[Room] => array()
[Place] => array(
[User] => array(
[mobile] => /* here after find not working it should content country code + mobile */
)
)
)
?>
【问题讨论】:
-
不要使用任何递归。在 AppModel 中将其设置为 -1,然后在需要其他关联数据时使用 Containable Behavior。
标签: cakephp cakephp-2.0 cakephp-model