Skip to content

Instantly share code, notes, and snippets.

@vietdien2005
Forked from alexander-torosh/QueryBuilderQuery.php
Created December 14, 2016 05:11
Show Gist options
  • Save vietdien2005/a247034491f8cf6d31564c6ba104937a to your computer and use it in GitHub Desktop.
Save vietdien2005/a247034491f8cf6d31564c6ba104937a to your computer and use it in GitHub Desktop.
Example of using Phalcon Query Builder and Columns method
<?php
$qb = $this->modelsManager->createBuilder()
->columns(['e.*', 'i.*'])
->addFrom('Backend\Models\Event', 'e')
->innerJoin('Backend\Models\Image', 'e.id = i.event_id', 'i')
->where('e.id = :id:', ['id' => $some_id]);
$entries = $qb->getQuery()->execute();
if ($entries->count()) {
foreach ($entries as $el) {
echo "title = " . $el->e->getTitle() . "<br>";
echo "joined image = " . $el->i->getImageSource();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment