i have comments function,i have “status” field in comments table
..i want to check this specific field value if it is equal to 0
or not in the controller..someone help me please to correct this code
function admin_publish ($id = null){
if (!$id) {
// set flash message
$this->Session->setFlash('Invalid id for Location','default',
array('class' => 'flash_bad'));
// redirect
$this->redirect(array('action'=>'admin_index'));
}else{
// if comment status field 0
if($comments['Comment']['status']== null){
// change status from 0 to 1
$this->Comment->saveField('status',1);
// set flash message
$this->Session->setFlash('The Comment was successfully
Published.');
} else {
$this->Comment->saveField('status', 0);
// set flash message
$this->Session->setFlash('The Comment could not be NotPublished.');
}
// redirect
$this->redirect(array('action'=>'admin_index'));
}
}
Try:
$commentData = $this->Comment->findById($commentId, "Comment.status"); $commentStatus = $commentData["Comment"]["Status"]; if(empty($commentStatus)) { //its zero } else { //its not zero }Hope it helps