在zend框架2中需要自定义连接查询的帮助

时间:2016-06-18 08:59:18

标签: zend-framework

我对多列显示的zend 2连接查询感到困惑,并且无法显示那些列

StudTable.php

public function custom_query() {
        $select = new Select();
        $select->from(array('s' => 'stud'));
        $select->columns(array('s.id','a.artist', 's.name', 's.sem','s.age'));
        //$select->where(array('id' => 14));

        $select->join(array('a' => 'album'),
                    'a.id = s.album_id');
        $select->order('s.id DESC'); 
        $select->limit(5);

        return $resultSet = $this->tableGateway->selectWith($select);
    }

index.phtml

<ul>
    <?php foreach ($this->customeObject as $obj_cus) : ?>
        <li>ID: <?php echo $obj_cus->id?>| Artist: <?php echo $obj_cus->artist?> | Name:<?php echo $obj_cus->name?> | Sem:<?php echo $obj_cus->sem?> | Age:<?php echo $obj_cus->age?></li>
    <?php endforeach; ?>
    </ul>

但它显示以下错误 enter image description here

2 个答案:

答案 0 :(得分:1)

columns方法签名如下所示:

public function columns(array $columns, $prefixColumnsWithTable = true)

因此默认情况下启用了prefixColumnsWithTable。

这就是您收到错误消息的原因:

  

未知列s.s.id

因此解决此问题的最简单方法是将false作为第二个参数传递给列:

$select->columns(array('s.id','a.artist', 's.name', 's.sem','s.age'), false);

答案 1 :(得分:1)

[{
  "id": "1",
  "title": "Question1",
  "ManagerComment": "This was a Job Wel Done",
  "EmployeeComment": "Wow I am Surprised",
  "ParticipantArray": [{
      "id": "1",
      "comment": "Oh i Dont think So"
    }, {
      "id": "2",
      "comment": "Oh i believe the same"
    }

  ]
}, {
  "id": "2",
  "title": "Question 2",
  "ManagerComment": "This was a Job Wel Done 1",
  "EmployeeComment": "Wow I am Surprised 1",
  "ParticipantArray": [{
      "id": "1",
      "comment": "Oh i Dont think So 1"
    }

  ]
}];