Skip to content

Instantly share code, notes, and snippets.

@ijmorgado
Created January 28, 2013 04:58
Show Gist options
  • Save ijmorgado/4653180 to your computer and use it in GitHub Desktop.
Save ijmorgado/4653180 to your computer and use it in GitHub Desktop.
That's a small function for a Table Gateway model that executes a SQL Join between data of 2 tables and returns the resultset as an array....simply but useful when we work with multiples tables and relationships......It works for ZF2....
public function getOrderedByCategory(){
$sql = new Sql($this->tableGateway->getAdapter());
$select = $sql->select('alb_album')->where('alb_album.activo = 1 ORDER BY alb_album.id_categoria ASC');
$join = $select->join('alb_categoria','alb_album.id_categoria = alb_categoria.id_categoria',array('nombre_categoria'=>'nombre'));
$statement = $sql->prepareStatementForSqlObject($join);
$result = $statement->execute();
$rows = array_values(iterator_to_array($result));
return $rows;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment