Aim : Send an Http request as an array (i'm looking to the uri syntax if it's possible to send an array by the header of the Http)
Server Side
ProfilHandler.php My Profil Handler
/**
* 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 My Profil Controller
/**
* 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);
}
Yes, it is possible. For example:
Construct url like this:
url -> http://your-app.dev/app_dev.php/some/route/?options[city]=1231&options[county]=3432
then in controller for some/route
action you can get
$arr = $request->get('options', array());
And then $arr
should conatin:
Array
(
[city] => 1231
[county] => 3432
)
[Edit]:
Maybe try this:
Remove requirements for sector
(or set it to match comma separeted list requirements="[\w,]+"
:
* @Annotations\QueryParam(name="sector", default="IT", description="How many pages to return.")
Then construct url with sector
as an comma separated list, for example
?offset=5&limit=10§or=IT,HEALTH
And inside controller retrive it like this:
$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);
}