CakePHP:没有收到数据

时间:2015-10-16 17:51:39

标签: php cakephp

我收到一条“没有收到数据”(ERR_EMPTY_RESPONSE),代码如下:

/**
 * afterFind - anytime Cake finds an entry in the DB
 * automatically fill in "sendto" field
 * this contains all of the email addresses for the member
 *
 * return @results
*/
public function afterFind($results, $primary = false) {
    foreach ($results as $key => $val) {
        if (isset($val['Member']['id'])) {
            $results[$key]['Member']['sendto'] = $this->getEmailsByMemberId($val['Member']['id']);
        }
    }
    return $results;
}

/*
 * Get a list of email addresses for the user
 * For now, return a dummy list
 *
*/
public function getEmailsByMemberId($memberId) {
        $this->contain();

        $member = $this->find('first', array('conditions' => array('id' => $memberId)));
        if(! $member) {
                return false;
        }

        $emails = $member['Member']['email'];

        if(isset($member['Member']['work_email'])) {
                $emails .= ";" . $member['Member']['work_email'];
        }

        return $emails;
}

它与getEmailsByMemberID()中的$ member =调用有关。如果我注释掉这一行,代码运行没有错误。知道我为什么会收到这个错误吗?基本上,我想检查数据库

1 个答案:

答案 0 :(得分:1)

正如AgRizzo所说,afterFind被召唤了很多次。您需要使用afterFind密钥在getEmailsByMemberId()中停用callbacks回调。

  

回调键允许您禁用或指定应该运行的回调。禁用beforeFind& afterFind回调设置'callbacks'=>在你的选择中是假的。您还可以将callbacks选项设置为'before'或'after',以仅启用指定的回调。

您可以在此处阅读:http://api.cakephp.org/2.7/source-class-Model.html#2926-3004