i suggest to change your solution
Userlike Model
public function hasliked($postId, $userId) {
return !empty($this->find('count', array('conditions' => array('post_id' => $postId, 'user_id' => $userId))));
}
UserlikesController
public function hasliked($postId) {
if (empty($this->request->params['requested'])) {
throw new ForbiddenException();
}
$this->set('hasliked',$this->User->hasliked($postId,$this->Auth->user('id')));
}
In your view
<?php if($hasliked) :?>
<?php echo $this->Html->link('Dislike', array('controller' => 'userlikes', 'action' => 'dislike', $postId)); ?>
<?php else: ?>
<?php echo $this->Html->link('Like', array('controller' => 'userlikes', 'action' => 'like', $postId));; ?>
<?php endif;?>