Skip to content

Instantly share code, notes, and snippets.

@kabdessamad1
Created July 16, 2015 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kabdessamad1/64f961b24f099743aaf5 to your computer and use it in GitHub Desktop.
Save kabdessamad1/64f961b24f099743aaf5 to your computer and use it in GitHub Desktop.
Populate a php object from db using doctrine dbal and silex
<?php
namespace Webomattic\Entity;
class Service {
private $id;
private $service;
private $description;
private $icon;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
public function getService()
{
return $this->service;
}
public function setService($service)
{
$this->service = $service;
}
public function getDescription()
{
return $this->description;
}
public function setDescription($description)
{
$this->description = $description;
}
public function getIcon()
{
return $this->icon;
}
public function setIcon($icon)
{
$this->icon = $icon;
}
}
<?php
namespace Webomattic\Repository;
use Doctrine\DBAL\Connection;
use Webomattic\Entity\Service;
class ServiceRepository implements RepositoryInterface
{
private $db;
private $query;
public function __construct(Connection $db)
{
$this->db = $db;
$this->query = $this->db->createQueryBuilder();
}
public function getAll()
{
$stmt = $this->query->select("s.*")
->from('services', 's')
->orderBy('s.id', 'ASC')
->execute();
return $stmt->fetchAll(\PDO::FETCH_CLASS, 'Webomattic\Entity\Service');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment