cakephp找到all和afterFind方法

时间:2015-05-13 17:00:43

标签: cakephp model-view-controller belongs-to findall

我的模型有一个belongsTo变量,find和一个afterFind都在玩。问题是,当afterFind被注释掉时,find工作正常,但是一旦它在游戏中,find只返回" true",而不是一个对象数组。如果有人遇到过这个问题,请通知我!

型号:



     public $belongsTo = array(
            'User' => array(
                'className' => 'User',
                'foreignKey' => 'user_id',
                'conditions' => '',
                'fields' => '',
                'order' => ''
            ),
            'ContactCategory' => array(
                'className' => 'ContactCategory',
                'foreignKey' => 'contact_category_id',
                'conditions' => '',
                'fields' => '',
                'order' => ''
            ),
            'State' => array(
                'className' => 'State',
                'foreignKey' => 'state_id',
                'conditions' => '',
                'fields' => '',
                'order' => ''
            )
        );

        public function getContact($id)
        {
            if ($id) {
                $contact = $this->find('first', array('conditions' => array('Contact.id' => $id), 'fields' => array('id', 'image')));
                return $contact;
            } else {
                return false;
            }
        }

        public function afterFind($results = array(), $primary = false)
        {
            foreach ($results as $key => &$val) {
                if (isset($val['Contact'])) {
                    $this->decryptFields($val['Contact'], $this->fieldsToEncrypt());
                }
            }
        }

0 个答案:

没有答案