2011-12-19 50 views
0

我有评论功能,我有评论表 ..中的“状态”字段..如果它等于0 或不在控制器中,我想检查此特定字段值。有人请帮助我改正这个代码如何检查控制器中的特定字段值

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')); 
     } 
     } 

回答

0

尝试:

 
$commentData = $this->Comment->findById($commentId, "Comment.status"); 
$commentStatus = $commentData["Comment"]["Status"]; 
if(empty($commentStatus)) { 
    //its zero 
} 
else { 
    //its not zero 
} 

希望它可以帮助

+0

苏德赫感谢帮助...它是作品 – user1080247

相关问题