我正在 symfony2 中编写 web 服务,但我在输出方面遇到了一些问题,因为它给出了空白输出。
class DefaultController extends Controller {
/**
*
* @Route("/webservices/activity/{id}", name="user_json_activity")
* @Method("get")
*/
public function activityAction($id) {
$em = $this->getDoctrine()->getEntityManager();
$list = $em->getRepository('FitugowebserviceBundle:activity')->findOneById($id);
$r_array = $this->routes2Array($list);
$r = array('activity' => $r_array);
return new Response(json_encode($r));
}
private function routes2Array($routes) {
$points_array = array();
foreach ($routes as $route) {
$r_array = array('activity' => $route->getActivity(),
'icon' => $route->getIcon());
$points_array[] = $r_array;
}
return $points_array;
}
}
当我尝试获取 id=1 http://domain.org/fitugo/web/app_dev.php/webservices/activity/1的数据时,它给出的输出如下
{“活动”:[]}