CdbCriteria不能同时用于两个字段

时间:2013-09-25 15:51:01

标签: php yii

我使用以下代码在高级搜索表单中创建了4个radiobutton。

<div class="row">
        <?php #echo $form->label($model,'ReviewedDate'); ?>     
                <?php echo $form->radioButtonList($model, 'ReviewedDate', 
        array('1' => 'Reviewed', '' => 'Not Reviewed')
    ); ?>
    </div>

       <div class="row"> 
                <?php echo $form->radioButtonList($model, 'Approved', 
        array('0' => 'Rejected', '1' => 'Approved')
    ); ?> 
    </div>   

所以现在我在模型中创建了一些标准,用于过滤gridview以根据radiobutton值显示行。

if($this->ReviewedDate != '') 
                {
                $criteria->addCondition('ReviewedDate ' . ($this->ReviewedDate=='1' ? 'IS NOT NULL' : 'IS NULL'));
                $criteria->addCondition('updateddate > createddate');
                $criteria->compare('revieweddate','0000-00-00 00:00:00');
                }
                else 
                {
                $criteria->addCondition('updateddate = createddate');    
                $criteria->addCondition('ReviewedDate IS NULL');
                }



if (isset($this->Approved) && !empty($this->Approved)) {

                        $criteria->addCondition("approved='" . $this->Approved . "'");
                        $criteria->condition = ' (updateddate > createddate) AND (revieweddate IS NOT NULL) and approved = 1 ';
                }
                else {

                        $criteria->addCondition("approved='" . $this->Approved . "'");
                        $criteria->condition = ' (updateddate > createddate) AND (revieweddate IS NOT NULL) and approved = 0 ';
                }

上述代码工作正常,如果评论了审核日期条件或评论了批准的条件,则会相应地显示行。但是,这两个标准不能同时发挥作用。 当我尝试同时使用这两个标准时,其中一个标准起作用 1.现在,我想为每个选项创建单独的单选按钮(我需要4个radiobutton批准,拒绝,审核,未审核)。
我希望无线电按钮能够在不重叠的情况下为每个标准工作 我怎么能这样做

1 个答案:

答案 0 :(得分:0)

通过设置$criteria->condition,您实际上撤消了所有addConditioncompare来电。请改为使用其他addCondition来电。