系统当中是可以自定义查询语句,用在级联查询当中比较好

目录
show

在 zhaoshang 这个项目当中,有 app/c/api.php 文件项目。仔细参考下面的代码。

function get( $apistr = '')
  {

    $p = _decode($apistr);
    $type= $p['type']?$p['type']:'deal';
    $order_by = $p['order_by']?$p['order_by']:'investDate';
    $desc = $p['desc']?$p['desc']:'desc';
    $field = $p['field']?$p['field']:false;
    $val = $p['val']?$p['val']:false;
    $page = $p['page']?$p['page']:1;
    $page_size = $p['page_size']?$p['page_size']:20;
    //$this->data = $data = load('m/config_m')->key($this->mod);
    $q = load('m/entity_m');
    $q->filter = ' 1 ';

    if($field){
      $query = " select e.* from entity e inner join entity_index i on e.uuid = i.eid
      where i.type= '$type' and  i.field = '$field' and i.val = '$val'";
    }
    else{
      $query = " select e.* from entity e inner join entity_index i on e.uuid = i.eid
      where i.type= '$type' and  i.field = '$order_by' order by i.val $desc limit $page,$page_size";
    }

    $ret = $q->db->query($query);

    die(_encode($ret));
  }