Cakephp 如何检查控制器中的特定字段值

Cakephp 如何检查控制器中的特定字段值,cakephp,controller,cakephp-1.3,Cakephp,Controller,Cakephp 1.3,我有注释功能,注释表中有“状态”字段 ..我想检查此特定字段值是否等于0 或者不在控制器中..请有人帮我更正此代码 function admin_publish ($id = null){ if (!$id) { // set flash message $this->Session->setFlash('Invalid id for Locati

我有注释功能,注释表中有“状态”字段 ..我想检查此特定字段值是否等于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'));
        }
        } 
尝试:

$commentData=$this->Comment->findById($commentId,“Comment.status”); $commentStatus=$commentData[“Comment”][“Status”]; if(空($commentStatus)){ //零度 } 否则{ //不是零 } 希望能有帮助

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