doumu6941 2015-08-27 12:18
浏览 48
已采纳

高级搜索选项在gridview中不起作用(使用YII框架)

I am new at coding in php and using Yii Framework.I am unable to find the solution.I have a search option in a page where some information are shown of many users.For searching purpose there is a search function in my model.Here is the search function code.

public function search()
    {


        $criteria=new CDbCriteria;
        $criteria->compare('cv_id',$this->cv_id,true);
        $criteria->compare('user_id',$this->user_id,true);
        $criteria->compare('job_title_id',$this->job_title_id);
        $criteria->compare('cv_type',$this->cv_type,true);
        $criteria->compare('version_id',$this->version_id,true);
        $criteria->compare('upload_date',$this->upload_date,true);
        $criteria->compare('update_date',$this->update_date,true);
        $criteria->compare('file_name',$this->file_name,true);
        $criteria->compare('next_review_date',$this->next_review_date,true);
        $criteria->compare('review_status',$this->review_status,true);
        $criteria->compare('file_location',$this->file_location,true);
        $criteria->compare('is_current',$this->is_current,true);
        $criteria->compare('status',$this->status,false);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
                'sort'=>array(


        'defaultOrder'=>'upload_date DESC'
        )
        ));
    }

this function doesn't work if i declare a condition within the search function.I need to declare the condition for showing the current data of the user in the page.here is the condition code:

$criteria->condition = "is_current='yes'";

If i omit this condition code line the search function works fine.But i need this code line to show current data of the user.So what can i do...does any one have a solution....Please provide me with code example as i am not good at coding....

  • 写回答

1条回答 默认 最新

  • duafagm1066 2015-08-27 21:51
    关注

    CDbCriteria has several methods to specify conditions, e.g. compare, addColumnCondition, ... which will add each condition to the condition property of CDbCriteria.

    I assume that you declared your condition after all the compare conditions, which would overwrite all of the previous ones.

    I suggest to replace the current compare condition for is_current as follows:

    $criteria->compare('is_current',$this->is_current,true);
    

    by

    $criteria->compare('is_current', 'yes');
    

    Keep in mind to disable the is_current search field in the gridview, because that input won't be taken into account anymore.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作