目标:发送 Http请求作为数组(我正在寻找 uri语法如果可以通过 Http 的标题发送数组
服务器端
ProfilHandler.php 我的Profil处理程序
/**
* Get a list of News.
*
* @param int $limit the limit of the result
* @param int $offset starting from the offset
* @param array $sector get profils by sectors
*
* @return array
*/
public function all($limit = 5, $offset = 0,$sector)
{
return $this->repository->findBy(array(), null, $limit, $offset, $sector);
}
ProfilController.php 我的Profil控制器
/**
* List all profiles.
*
* @ApiDoc(
* resource = true,
* statusCodes = {
* 200 = "Returned when successful"
* }
* )
*
* @Annotations\QueryParam(name="offset", requirements="\d+", nullable=true, description="Offset from which to start listing profiles.")
* @Annotations\QueryParam(name="limit", requirements="\d+", default="10", description="How many pages to return.")
* @Annotations\QueryParam(name="sector", requirements="\d+", default="IT", description="How many pages to return.")
*
* @Annotations\View(
* templateVar="profiles"
* )
*
* @param Request $request the request object
* @param ParamFetcherInterface $paramFetcher param fetcher service
*
* @return array
*/
// ....
public function getProfilsAction(Request $request, ParamFetcherInterface $paramFetcher)
{
$offset = $paramFetcher->get('offset');
$offset = null == $offset ? 0 : $offset;
$limit = $paramFetcher->get('limit');
$secteur = $paramFetcher->get('sector');
return $this->container->get('genius_profile.profil.handler')->all($limit, $offset,$sector);
}
答案 0 :(得分:3)
是的,有可能。例如:
构建这样的url:
网址 - > http://your-app.dev/app_dev.php/some/route/?options[city]=1231&options[county]=3432
然后在控制器中进行some/route
操作
$arr = $request->get('options', array());
然后$arr
应该坚持:
Array
(
[city] => 1231
[county] => 3432
)
<强> [编辑]:强>
也许试试这个:
删除sector
的要求(或将其设置为与逗号分隔列表requirements="[\w,]+"
匹配:
* @Annotations\QueryParam(name="sector", default="IT", description="How many pages to return.")
然后使用sector
构造url作为逗号分隔列表,例如
?offset=5&limit=10§or=IT,HEALTH
内部控制器会像这样重复:
$secteur = explode(',', $paramFetcher->get('sector'));
<强> [EDIT2]:强>
public function all($limit = 5, $offset = 0,$secteur) {
if (sizeof($secteur)>=1){
return $this->repository->findBy(array('secteur' => $secteur), array('secteur' => 'ASC'));
}
return $this->repository->findBy(array(), null, $limit);
}