0

I am using a FOSRestBundle and I am pretty new in Symfony.

I've been following some exemples I've seen but I can't add more than one parameter in the request.

For example

/**
     *  
     * @param  string $id Identifier
     * @return [type]     [description]
     *
     * @ApiDoc()
     */
    public function getProductsAction($id)
    {
        return myfunction($id);
    }

works fine, but if I want to do a variation like this:

 /**
     *  
     * @param  string $id Identifier
     * @return [type]     [description]
     *
     * @ApiDoc()
     */
    public function getProductsAction($id, $month)
    {
        return myfunction($id, $month);
    }

It doesn't work. It identifies only the $id

There is any limitation I am not aware? or some extra configuration beyond the simple modification I did?

1 Answer 1

1

When you write

/**
 *  
 * @param  string $id Identifier
 * @return [type]     [description]
 *
 * @ApiDoc()
 */
public function getProductsAction($id)
{
    return myfunction($id);
}

it's equivalent to

use FOS\RestBundle\Controller\Annotations\Get;

/**
 * @Get("/products/{id}")
 * @param  string $id Identifier
 * @return [type]     [description]
 *
 * @ApiDoc()
 */
public function getProductsAction($id)
{
    return myfunction($id);
}

Symfony maps automatically the route and parameter.

But when you write

/**
 *  
 * @param  string $id Identifier
 * @return [type]     [description]
 *
 * @ApiDoc()
 */
public function getProductsAction($id, $month)
{
    return myfunction($id, $month);
}

Symfoy doesn't know what to do with your $month parameter, you need to tell it

use FOS\RestBundle\Controller\Annotations\Get;

/**
 * @Get("/products/{id}/{month}")
 * @param  string $id Identifier
 * @return [type]     [description]
 *
 * @ApiDoc()
 */
public function getProductsAction($id, $month)
{
    return myfunction($id, $month);
}
Sign up to request clarification or add additional context in comments.

2 Comments

The @get is an annotation from which symfony component? I am getting a non imported use statement.
@MatheusOliveira it's the annotation from FOSRestBundle, i've included it in the 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.