/** * @return \SplObjectStorage */ public function fetchAll() { $objectStorage = new \SplObjectStorage(); $query = 'SELECT `id`, `name` FROM `person` ORDER BY `id` ASC;'; $stmt = $this->getDb()->prepare($query); $this->executeStatement($stmt); while (list($id, $name) = $stmt->fetch(\PDO::FETCH_NUM)) { $person = new Model\Person(); $person->setId($id); $person->setName($name); $objectStorage->attach($person); } return $objectStorage; }
private function postAction(Http\Request $request, Http\Response $response) { $response->addHeader(new Http\Header('Content-Type', 'application/json; charset=utf-8')); try { $person = new Model\Person(); $person->setName($request->getPost('name')); /* @var $personMapper \Foodalizr\Mapper\PersonMapper */ $personMapper = $this->getMapper('\\Foodalizr\\Mapper\\PersonMapper'); $personMapper->save($person); $response->setContent(new \Knid\Json\Model($person)); } catch (\OutOfBoundsException $e) { $reponse->setContent(json_encode($e)); } return $response; }