Domanda

I have some code in cakephp which produces an error.

Here is the PHP Controller:

$this->loadModel( 'Vote' ); //Newly added by amit start
$vote=$this->Vote->getVote($id,$uid);
$this->set('vote',$vote);
$voteCount = count($vote);
$this->set('voteCount',$voteCount);

$voteShow = $this->Vote->find('all', array(
    'fields' => array('SUM(Vote.score)   AS score','count(id) as countId'),
     'conditions'=>array('Vote.type_id'=>$id),
));
$this->set('voteShow',$voteShow);

model:

public function getVote($id,$uid) {
    if (empty($conditions))
        $conditions = array('Vote.type' => 'blog',
                            'Vote.type_id' => $id,
                            'Vote.user_id' => $uid);

    $users = $this->find('all', array('conditions' => $conditions,
        'order' => 'Vote.id desc'
    ));
    return $users;
}

That code produces this error:

Error : An internal error has occurred

What does this error mean?

È stato utile?

Soluzione

I enabled debug mode: Configure::write('debug', 2); in core.php and it solved my problem.

Altri suggerimenti

In my case debug mode was Configure::write('debug', 0); on live server in core.php.

I set it to Configure::write('debug', 1); and no error was shown this time.

So I again changed my debug mode to Configure::write('debug', 0); because I don't want to show debug error on my live site.

This time no error message shows up.

So just changing the debug mode once in core.php get rid of this error in my case.

If you change your debug mode to 1 and then run those functions which you have changed on local, CakePHP will refresh the cache for all those models which include in those functions. Now you can change back to Configure::write('debug', 0).

Do NOT set Configure::write('debug',2) in production, or you could end up writing sensitive data (such as Query) to user when there will be an error, the reason why debug 2 works is because items in the CACHE are not taken in consideration anymore, so it works. Just delete the cache and leave DEBUG to 0 in production VERY IMPORTANT

Cache can be found here: tmp/cache/

Then again, do NOT delete the 3 folder you'll find there, just delete their content.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top