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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题