I am just starting out with Zend Framework 2 and I came across roadblock.
In this simplest expression, the fetchAll function works:
public function fetchAll() { $resultSet = $this->tableGateway->select(); return $resultSet; }
However, when I try to mix in the connection as follows:
public function fetchAll() { $sql = new Sql($this->tableGateway->getAdapter()); $select = $sql->select(); $select->from('Entreprise') ->columns(array('id', 'nom', 'categorie_id')) ->join(array('C' => 'Categorie'), 'categorie_id = C.id', array('categorie' => 'nom'), \Zend\Db\Sql\Select::JOIN_INNER); $resultSet = $this->tableGateway->selectWith($select); return $resultSet; }
Summary request:
SELECT "Entreprise"."id" AS "id", "Entreprise"."nom" AS "nom", "Entreprise"."categorie_id" AS "categorie_id", "C"."nom" AS "categorie" FROM "Entreprise" INNER JOIN "Categorie" AS "C" ON "categorie_id" = "C"."id"
Table names, columns are beautiful, because the query does not cause an error, but simply returns an empty result set. Even deleting the connection and simply abandoning the following code does not help.
public function fetchAll() { $sql = new Sql($this->tableGateway->getAdapter()); $select = $sql->select(); $select->from('Entreprise'); $resultSet = $this->tableGateway->selectWith($select); return $resultSet; }
Because of what, I believe that this is just something wrong with the way I get the adapter or create an instance of select, but I just can not understand it or find any solution.
Can someone help me understand what I am doing wrong?