Created
July 16, 2015 19:22
-
-
Save kabdessamad1/64f961b24f099743aaf5 to your computer and use it in GitHub Desktop.
Populate a php object from db using doctrine dbal and silex
This file contains hidden or 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
<?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; | |
} | |
} |
This file contains hidden or 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
<?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