FOS\RestBundle\Controller\Annotations\Route ignores route prefix #219

jamhall opened this Issue Mar 30, 2012 · 6 comments


None yet
6 participants

jamhall commented Mar 30, 2012

The route annotations appear to ignore route prefixes.

If i go to http://localhost/institutes.json, I get a json encoded list of institutes. This is wrong.

If I go to http://localhost/api/v1/institutes.json I get a 404 not found which is not what I want.

Here's my config:

namespace MyCompanyMyProjectBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\Controller\Annotations\Route,

class ApiController extends Controller

     * @Route("/institutes", defaults={"_format" = "json"})
     * @Get
    public function institutesAction()
        $data =   $this->getDoctrine()
        return array("data"=>$data);

     * @Route("/institute/{id}", defaults={"_format" = "json"})
     * @Get
    public function instituteAction($id)
        $data =   $this->getDoctrine()
        return array("data"=>$data);

Project routing.yml:

    type:         rest
    resource:     MyCompany\MyProjectBundle\Controller\ApiController
    prefix:       /api/v1/
    name_prefix:  api_

src config.yml:

            rss: false
            html: false
            xml: false
            json: true
            html: false
            json: false
            html: true
        failed_validation: HTTP_BAD_REQUEST
        default_engine: twig
        view_response_listener: force
        default_priorities: ['json', html, '*/*']
        fallback_format: json
        prefer_extension: true
            'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
    view:    { annotations: false }
    router:  { annotations: true }

everzet was assigned Mar 30, 2012

jamhall commented Mar 30, 2012

I even tried putting

* @Prefix("api/v1")
* @NamePrefix("api_")

at the top of the class (i made sure to import the NamePrefix and Prefix annotations). but this made no difference. Alas

thvd commented Apr 7, 2012

Indeed I have actually the same problem, I'm using the 0.6 branch with the latest Symfony release. (2.0.12)

JohnLoo commented Apr 14, 2012

I am having the same issue : name_prefix is ignored.

I think the bug resides in the file FOS\RestBundle\Routing\Loader\RestRouteProcessor.
Since the fusion of the branch master and 0.6, you added the class RestRouteLoader20 in order to correct the change of the interface LoaderInterface.
Line 54, you test that the loader is an intance of RestRouteLoader and I think you should also test that the loader is an instance of RestRouteLoader20 ?


lsmith77 commented Apr 14, 2012

@JohnLoo the ticket was opened before we did this change.
but i just pushed a fix for the issue you noted


intel352 commented Apr 7, 2013

Shouldn't this be closed now? [EDIT] Nevermind, this issue is still present afaict. Setting prefix at top of class via annotation, or setting it in bundle routing.yml, sees the prefix ignored in either location.

lsmith77 closed this Apr 7, 2013

lsmith77 reopened this Apr 7, 2013


lsmith77 commented Apr 7, 2013

@intel352 can you look into writing a test (and a fix)?

lsmith77 closed this in da58654 Apr 7, 2013

@lsmith77 lsmith77 added a commit that referenced this issue Apr 7, 2013

@lsmith77 lsmith77 Merge pull request #424 from intel352/patch-1
Fixes #219 - route prefix ignored
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment