1
votes

My routing.yml:

user_user:
    resource: "@UserUserBundle/Resources/config/routing.yml"
    prefix:   /user

book_book:
    resource: "@BookBookBundle/Resources/config/routing.yml"
    prefix:   /book

index_index:
    resource: "@IndexIndexBundle/Resources/config/routing.yml"
    prefix:   /


app:
    resource: "@AppBundle/Controller/"
    type:     annotation

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

app_api:
    resource: "@AppBundle/Controller/Api"
    type:     annotation

mvms_api:
    type:     rest
    prefix:   /api
    resource: "@AppBundle/Resources/config/api-routing.yml"

My

api-routing.yml:

blog_api_articles:
    type: rest
    resource: "@AppBundle/Controller/ArticlesController.php"
    name_prefix:  api_article_


blog_api_reviews:
    type: rest
    resource: "@AppBundle/Controller/ReviewsController.php"
    name_prefix:  api_reviews_


api_reviewsPut:
    type: rest
    resource: "@AppBundle/Controller/PutController.php"
    name_prefix:  api_put_

My php bin/console debug:router

...
  api_article_get_article             GET        ANY      ANY    /api/articles/{id}.{_format}
  api_reviews_get_review              GET        ANY      ANY    /api/reviews/{id}.{_format}

The last entry in my api-routing doesn't appear to be working/showing ...

//This works fine
    class ReviewsController extends Controller
{

    /**
     * Note: here the name is important
     * get => the action is restricted to GET HTTP method
     * Article => (without s) generate /articles/SOMETHING
     * Action => standard things for symfony for a controller method which
     *           generate an output
     *
     * it generates so the route GET .../articles/{id}
     */
    public function getReviewAction($id)
    {

            $someId = $id;
            $rv = $this->getDoctrine()->getManager();
            $review = $rv->createQuery(
                'SELECT *  FROM AppBundle:Something r WHERE r.id= :id')->setParameter('id', $someId);

            $reviews = $review->getResult();
        if (empty($reviews)) {
            return array('Data' => 'none');
        }
        else
            return $reviews;
    }




}


class PutController
{
    public function putReviewsPut($id)
    {

        $someId = $id;
        $rv = $this->getDoctrine()->getManager();
        $review = $rv->createQuery(
            'some query')->setParameter('id', $someId);

        $reviews = $review->getResult();
        if (empty($reviews)) {
            return array('Data' => 'none');
        }
        else
            return $reviews;
    }
}

When I enter new routes in the api-routing.yml the app just doesn't bother to take them into account. Thus I'm getting "No route found for \"GET /api/put/1\"", In Postman

I tried restarting the Server And also tried php bin/console cache:clear --env prod

Running Xampp on Windows 10 and using phpStorm for editor.

I was having exactly the same issue last night with api_reviews_ but somehow it decided to eventually work.

1
Did you try clear cache?Imanali Mamadiev
@ImanaliMamadiev YepИво Недев
It has something to do with plural ... There needs to be an S at the end somewhere. I'll elaborate if I understand itИво Недев

1 Answers

4
votes

You should use the suffix Action in the controller method.

So try this:

class PutController
{
    public function putReviewsPutAction($id)
    {

Instead of this:

class PutController
{
    public function putReviewsPut($id)
    {

Hope this help