Reputation: 849
I am getting a “No data received” (ERR_EMPTY_RESPONSE) with the following code:
/**
* 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;
}
It has to do with the $member = call in getEmailsByMemberID(). If I comment out this line, the code runs without error. Any idea why I'm getting this error? Basically, I want to check the database
Upvotes: 0
Views: 241
Reputation: 654
As AgRizzo told afterFind
is getting called lots of times. You need to disable afterFind
callback in getEmailsByMemberId()
by using callbacks
key.
The callbacks key allows you to disable or specify the callbacks that should be run. To disable beforeFind & afterFind callbacks set 'callbacks' => false in your options. You can also set the callbacks option to 'before' or 'after' to enable only the specified callback.
You can read about it here:http://api.cakephp.org/2.7/source-class-Model.html#2926-3004
Upvotes: 1