POST路由注释symfony2

时间:2016-03-29 06:28:27

标签: symfony routes

我正在尝试开发一个rest api,我对路由注释有问题,因为它运行良好,我的get代码如下

    /**
 * @QueryParam(name="offset", requirements="\d+", nullable=true, description="Offset from which to start listing pages.")
 * @QueryParam(name="limit", requirements="\d+", nullable=true, default="20", description="How many pages to return.")
 *
 * @View()
 *
 * @param Request               $request      the request object
 * @param ParamFetcherInterface $paramFetcher param fetcher service
 * GET Route annotation.
 * @Get("/users/")
 * @return array
 */
public function getUsersAction(Request $request, ParamFetcherInterface $paramFetcher)
{
    $offset = $paramFetcher->get('offset');
    $offset = null == $offset ? 0 : $offset;
    $limit = $paramFetcher->get('limit');

    return $this->container->get('user.handler')->all($limit, $offset);
}

对于帖子我不知道怎么做,我的代码如下,我想在url中添加用户的attribues,怎么做plz

         /**
* @View(template = "UserBundle:User:register.html.twig", statusCode = Codes::HTTP_BAD_REQUEST, templateVar = "form")
*
* @param Request $request the request object
* POST Route annotation.
* @Post("/users/")
* @return FormTypeInterface|View
*/
public function postUserAction(Request $request)
{
    try {
        $newUser = $this->get('user.handler')->post($request);

        $routeOptions = array(
                'id' => $newUser->getId(),
                '_format' => $request->get('_format')
        );

        return $this->routeRedirectView('get_user', $routeOptions, Codes::HTTP_CREATED);
    } catch (InvalidFormException $exception) {

        return $exception->getForm();
    }
}

1 个答案:

答案 0 :(得分:0)

您可以从请求中获取这些参数:

let array: [String] = ["♣️", "♦️", "❤️", "♠️"]
let index: Int = self.rawValue - 1
let symbol = array[index]
return symbol