afterFind不使用递归级别2

时间:2015-04-11 05:43:13

标签: cakephp cakephp-2.0 cakephp-appmodel

问题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个型号。 RoomPlaceUser

<?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 */
        )
    )
)
?>

1 个答案:

答案 0 :(得分:0)

绑定flyby时,$ reset可能存在问题。 http://api.cakephp.org/2.1/source-class-Model.html#868-910

请将$ reset设置为false。

$这 - &GT;模型 - &GT; bindModel(阵列(...),假);