swoole gets

控制器调用:

    function gets()
    {
        $model = Model('ap_pic');
        $model->select = ' id, size_type ';
        $gets['page'] = empty($_GET['page'])?0:intval($_GET['page']);
        $gets['pagesize'] = 2;
        $gets['where'] = " orders=1381392612 ";
        $gets['orwhere'] = " name=1381392612 ";        
        $pager = 2;
        $list = $model->gets($gets, $pager);
        echo "<pre>";
        var_dump($list);
        echo "</pre>";
        exit;
    }

调用了Model.php

    /**
     * 获取表的一段数据,查询的参数由$params指定
     * @param $params
     * @param $pager Pager
     * @return Array
     */
    public final function gets($params, &$pager=null)
    {
        if (empty($params))
        {
            throw new Exception("no params.");
        }

        $selectdb = new SelectDB($this->db);
        $selectdb->from($this->table);
        $selectdb->primary = $this->primary;
        $selectdb->select($this->select);

        if (!isset($params['order']))
        {
            $params['order'] = "`{$this->table}`.{$this->primary} desc";
        }
        $selectdb->put($params);

        if (isset($params['page']))
        {
            $selectdb->paging();
            $pager = $selectdb->pager;
        }

        return $selectdb->getall();
    }

selectDB.php中 function put($params)

    /**
     * 将数组作为指令调用
     * @param $params
     * @return null
     */
    function put($params)
    {
        if(isset($params['put']))
        {
            Error::info('SelectDB Error!','Params put() cannot call put()!');
        }
        //处理where条件
        if(isset($params['where']))
        {
            $wheres = $params['where'];
            if(is_array($wheres)) foreach($wheres as $where) $this->where($where);
            else $this->where($wheres);
            unset($params['where']);
        }
        //处理orwhere条件
        if(isset($params['orwhere']))
        {
            $orwheres = $params['orwhere'];
            if(is_array($orwheres)) foreach($orwheres as $orwhere) $this->orwhere($orwhere);
            else $this->$orwheres($orwheres);
            unset($params['orwhere']);
        }
        //处理walk调用
        if(isset($params['walk']))
        {
            foreach($params['walk'] as $call)
            {
                list($key,$value) = each($call);
                $this->_call($key,$value);
            }
            unset($params['walk']);
        }
        //处理其他参数
        foreach($params as $key=>$value)
        {
            $this->_call($key,$value);
        }
    }
原文地址:https://www.cnblogs.com/agang-php/p/4523932.html