yii 为什么使用 CDbCriteria类,$criteria->join为什么查出来的数据还是一个表里面的?

WBOY
Release: 2016-06-06 20:26:21
Original
1252 people have browsed it

这个是我在model文件里面写的一个方法。我想将一张表(t) 和 另一张表 c 做外连接(left join)。

<code>    public function pagination($limit, $condition, $order){
        $criteria = new CDbCriteria();
        $criteria->alias = 't';
        $criteria->order = $order;
        $criteria->select = 't.id, c.value';
        $criteria->addCondition($condition);
        $criteria->join = 'left join lp_site_conf as c on t.type=c.id';
        $result['listInfo'] = YiiData($this->findAll($criteria));
        $result['pageCount'] = $pages->getPageCount();
    }</code>
Copy after login
Copy after login

但是 现在查出来的数据是这样的

<code>array(10) {
  [0] => array(9) {
    ["id"] => string(2) "10"
    ["name"] => NULL
    ["type"] => NULL
    ["createuid"] => NULL
    ["createtime"] => NULL
    ["modifytime"] => NULL
    ["description1"] => NULL
    ["description2"] => NULL
    ["status"] => NULL
  }
  [1] => array(9) {
    ["id"] => string(1) "9"
    ["name"] => NULL
    ["type"] => NULL
    ["createuid"] => NULL
    ["createtime"] => NULL
    ["modifytime"] => NULL
    ["description1"] => NULL
    ["description2"] => NULL
    ["status"] => NULL
  }</code>
Copy after login
Copy after login

这些字段都是t表中的,根本没有leftjoin的表的字段,这是什么原因?

回复内容:

这个是我在model文件里面写的一个方法。我想将一张表(t) 和 另一张表 c 做外连接(left join)。

<code>    public function pagination($limit, $condition, $order){
        $criteria = new CDbCriteria();
        $criteria->alias = 't';
        $criteria->order = $order;
        $criteria->select = 't.id, c.value';
        $criteria->addCondition($condition);
        $criteria->join = 'left join lp_site_conf as c on t.type=c.id';
        $result['listInfo'] = YiiData($this->findAll($criteria));
        $result['pageCount'] = $pages->getPageCount();
    }</code>
Copy after login
Copy after login

但是 现在查出来的数据是这样的

<code>array(10) {
  [0] => array(9) {
    ["id"] => string(2) "10"
    ["name"] => NULL
    ["type"] => NULL
    ["createuid"] => NULL
    ["createtime"] => NULL
    ["modifytime"] => NULL
    ["description1"] => NULL
    ["description2"] => NULL
    ["status"] => NULL
  }
  [1] => array(9) {
    ["id"] => string(1) "9"
    ["name"] => NULL
    ["type"] => NULL
    ["createuid"] => NULL
    ["createtime"] => NULL
    ["modifytime"] => NULL
    ["description1"] => NULL
    ["description2"] => NULL
    ["status"] => NULL
  }</code>
Copy after login
Copy after login

这些字段都是t表中的,根本没有leftjoin的表的字段,这是什么原因?

我遇到了和你一样的问题,你是怎么解决的呢?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template