【发布时间】:2016-12-30 16:40:35
【问题描述】:
所以我有这个模块化的 web 应用程序,它具有与 zend 框架 1.12 集成的学说 2。
所以我想根据请求 uri 返回一个对象,例如:url/api/people/1,它根据他们的 id 返回一个人。
*旁注,我可以返回人的所有对象,我只想在用户输入数字后选择一个对象。
我尝试过的是从 url 中获取参数并将其传递给 find 函数,但是教义不理解这些通过 uri 传递的数字,并认为它们是动作。
if($this->getRequest()->isGet())
{
$request = $this->getRequest();
$id = $request->getParam('peopleId');
$em = $this->getEntityManager();
$peopleRepo = $em->getRepository('API\Entity\People');
$people = $peopleRepo->find(3); //$id goes into find function
$resultArray[] =
[
'id' => $people->getId(),
'firstname' => $people->getFirstName(),
'lastname' => $people->getLastName(),
"food" => $people->getFavoriteFood()
];
echo json_encode($resultArray, JSON_PRETTY_PRINT);
var_dump($people);
*****编辑***** 所以我添加了可以手动找到一个人的代码,但是我想通过 url 来做到这一点,我该如何实现呢?
【问题讨论】:
标签: php zend-framework orm doctrine-orm uri