Alexander Tepe
Alexander Tepe

Reputation: 190

Symfony "No route found"

I recently built a new symfony-project with one simple controller to read in a .csv file and output it's content to a template. I generated the bundle and the controller using the console and gave the controller the route "/browse". When trying to run, (127.0.0.1:8000/browse) it tells me: "No route found for "GET/browse"".

src/OpiumBundle/Controller/BrowseController.php

<?php

namespace OpiumBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class BrowseController extends Controller {

    /**
     * @Route("/browse")
     */
    public function indexAction() {
        $varPath = $this->get('kernel')->getRootDir().'/../var';
        return $this->render('OpiumBundle:Browse:index.html.php', array(
            // ...
        ));
    }

}

app/config/routing.yml

opium:
    resource: "@OpiumBundle/Resources/config/routing.yml"
    prefix: /

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

unfortunately I can't post output from my debug:console, because my rep is too low. but there are two empty spaces where I guess they shouldn't:

debug:router

opium_homepage             ANY      ANY      ANY    /                                  
homepage                   ANY      ANY      ANY    /

Upvotes: 4

Views: 26108

Answers (1)

Will B.
Will B.

Reputation: 18416

When using the yml option while generating a bundle, will result in a bundle routing.yml file being created with a Bundle:Default:index of bundle_homepage, and the config file being included as a resource in your app routing.yml file.

Check your src/OpiumBundle/Resources/config/routing.yml file and ensure it reads as.

opium_bundle:
    resource: '@OpiumBundle/Controller/'
    type: annotation

Alternatively edit your app/config/routing.yml file to read

opium:
    resource: "@OpiumBundle/Controller/"
    prefix: /
    type: annotation

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

Otherwise you will not be able to utilize annotation based routing and would need to manually add the routes to your routing.yml config files.

After making the changes clear your cache

php bin/console cache:clear

Check your routes to ensure that browse is included

php bin/console debug:router

Which should output

opium_browse_index   ANY   ANY   ANY   /browse

Upvotes: 8

Related Questions