2016-05-04 14:35:01 5416次浏览 3条回答 0 悬赏 10 金钱

yii中的where条件,如何单独提出来,该怎么写呢?举个例子:

public function actionIndex() {
        $where['status'] = 1;
        $where['id'] = 455;
        $model= new ActiveDataProvider([
            'query' => Fee::find()->where($where)->orderBy('id desc'),
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

像这样的,如果我想写where['status'],大于,小于,不等于,between,like,之类的该怎么写呢?

  • 回答于 2016-05-04 15:40 举报

    哈哈哈 这么写 。$where=array('id'=>1)之后就可以啦 单独提了出来 牛逼吧

    1 条回复
    回复于 2016-05-05 18:09 回复

    我知道咋写了,是这样的:

     $where = [
                'and',
                ['=', 'storeid', 3786],
                ['<', 'status', 3],
            ];
    

    想加几个就写几个,so 棒!

  • 回答于 2016-05-05 16:25 举报

    可以使用绑定参数的写法,第二种可以写很多

    Comment::find()->where(['id'=>118])->all();
    Comment::find()->where('id > :id', [':id'=>118])->all();
    Comment::find()->where(['>', 'id', '118'])->all();
    
    1 条回复
    回复于 2016-05-05 18:11 回复

    我是这么解决的:

     $where = [
                'and',
                ['=', 'storeid', 3786],
                ['<', 'status', 3],
            ];
    
您需要登录后才可以回答。登录 | 立即注册
小程府
经理

小程府 北京

注册时间:2016-03-23
最后登录:2021-02-09
在线时长:30小时31分
  • 粉丝13
  • 金钱255
  • 威望100
  • 积分1555

热门问题