【问题标题】:how to check specific field value in controller如何检查控制器中的特定字段值
【发布时间】:2011-12-19 04:31:07
【问题描述】:

我有 cmets 功能,我在 cmets 表中有“状态”字段 ..我想检查这个特定的字段值是否等于 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'));
        }
        } 

【问题讨论】:

    标签: cakephp controller cakephp-1.3


    【解决方案1】:

    试试:

    $commentData = $this->Comment->findById($commentId, "Comment.status"); $commentStatus = $commentData["评论"]["状态"]; 如果(空($commentStatus)){ //它的零 } 别的 { //它不为零 }

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2019-05-22
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多