How can I do a JOIN inside a Model Table with TableGateway?
I have this in my Model/NoticiasTable.php:
protected $tableGateway;
public function __construct(TableGateway $tableGateway) {
$this->tableGateway = $tableGateway;
}
public function fetchAll() {
$where = new Where();
$where->isNull('deleted_at');
$resultSet = $this->tableGateway->select(function (Select $select) use ($where) {
$select->join('news_photos', 'news_photos.news_id = news.id');
$select->where($where);
$select->order('date DESC');
});
return $resultSet;
}
It doesn't show any errors, but the result is empty... If I remove the "join" it works. So, how to use JOIN inside a Model Table?
This is how I do join tables.
For
$this->tableGatewayI have a separated class.Now inside the controller let's say that you want to show all X records for
indexAction().With pagination.
$this->getView()simply returns ViewModel. If you don't want pagination simply et the first parameter to false.$this->getTable()is a controller plugin with a factory which callsServiceManageroutside the controller keeping eveything simple.