Created
January 28, 2013 04:58
-
-
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....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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