0
votes

I am new to symfony2. I am creating a simple page for "Hello {Name}" and using WAMP. and my routing.yml is as follows

projectnew_bundle:
    resource: "@projectnew_bundle/Resources/config/routing.yml"
    type:     annotation
    prefix:   /start

and my @projectnew_bundle/Resources/config/routing.yml is as follows (projectnew_bundle is the namespace for \project\new_bundle in src folder) :

projectnew_bundle_hello:
    pattern:  start/hello/{name}
    defaults: { _controller: projectnew_bundle:Start:hello }

I have also registered the bundle projectnew_bundle in AppKernel.php using "new project\new_bundle\projectnew_bundle()" syntax. My \src\project\new_bundle\projectnew_bundle.php is as follows:

<?php

namespace project\new_bundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class projectnew_bundle extends Bundle
{
}

But, when I try to load the following URL : "http://localhost/symfony_project/Symfony/web/app_dev.php/start/hello/Riten" , it gives the 500 internal server error:

Cannot load resource "@projectnew_bundle/Resources/config/routing.yml". Make sure the "projectnew_bundle/Resources/config/routing.yml" bundle is correctly registered and loaded in the application kernel class.

2
To be sure, did you clear the cache (app/console cache:clear -env=dev)sglessard
I didn't use console.. But, I have cleared the Symfony/app/cache folder manually..Riten
Please guys give me the solution to fix the problemRiten
And btw. start using CamelCase not underscore_caseEmii Khaos

2 Answers

3
votes

Try removing type: annotation from routing.yml

EDIT:

Your app/cofig/routing.yml has

projectnew_bundle:
    resource: "@projectnew_bundle/Resources/config/routing.yml"
    prefix:   /start

*Note: I removed type: annotation

So you set prefix /start on any route included in projectnew_bundle/Resources/config/routing.yml

Then your @projectnew_bundle/Resources/config/routing.yml has:

projectnew_bundle_hello:
    pattern:  start/hello/{name}
    defaults: { _controller: projectnew_bundle:Start:hello }

which creates the route projectnew_bundle_hello with the pattern start/hello/{name} adding the prefix from app/config/routing.yml your final route is /startstart/hello/{name} and not /start/hello/{name} as you are expecting.

If you want your expected route to work you can remove start from @projectnew_bundle/Resources/config/routing.yml.

The command php app/console router:debug will show you what your routes actually are.

1
votes

If you change to type: annotation you have to change the resource path to the controller path.

projectnew_bundle:
resource: "@projectnew_bundle/Controller"
type:     annotation
prefix:   /start