2

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);
    }

1 Answer 1

3

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&sector=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);
}
Sign up to request clarification or add additional context in comments.

6 Comments

I don't understand. Why and where you need array?
Can't you just make a ?offset=5&limit=10&secteur=20 request?
@pazlux no .. i need to send sectors as array for example fetch profils by sectors equals IT,HEALTH !
Did you get an error? What is returned by $paramFetcher->get('sector')?
You need to pass $secteur in array to findBy. See second update of my answer.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.