0

I am trying to start on Symfony2 but ran into a problem right away following the Symfony 2 "the book" part "Creating pages in Symfony 2":

I did this:

Created the bundle

php app/console init:bundle "Acme\StudyBundle" src

*Added the namespace in app/autoload.php *

$loader->registerNamespaces(array(
    'Acme'                         => __DIR__.'/../src',
));

Initialized the bundle

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Acme\StudyBundle\AcmeStudyBundle(),
    );

    // ...

    return $bundles;
}

Created the routes in app/config.routing.yml and src/Acme/StudyBundle/Resources/config/routing.yml

# app/config/routing.yml
homepage:
    pattern:  /
    defaults: { _controller: FrameworkBundle:Default:index }

hello:
    resource: "@AcmeStudyBundle/Resources/config/routing.yml"


# src/Acme/StudyBundle/Resources/config/routing.yml
hello:
    pattern:  /hello/{name}
    defaults: { _controller: AcmeStudyBundle:Hello:index }

Created the controller

// src/Acme/StudyBundle/Controller/HelloController.php

namespace Acme\StudyBundle\Controller;
use Symfony\Component\HttpFoundation\Response;

class HelloController
{
    public function indexAction($name)
    {
        return new Response('<html><body>Hello '.$name.'!</body></html>');
    }
}

When I load the page: http://localhost/app_dev.php/hello/Ryan Symfony gives me an exception:

Unable to find controller "AcmeStudyBundle:Hello" - class "Acme\StudyBundle\Controller\HelloController" does not exist.

I got over the code several times but cannot find anything wrong.

1
  • Try changing AcmeStudyBundle:Hello:Index to StudyBundle:Hello:Index? Commented Apr 15, 2011 at 13:52

3 Answers 3

6

just add

<?php

in the beginning of your controller file : src/Acme/StudyBundle/Controller/HelloController.php

it's solved the problem to me.

Sign up to request clarification or add additional context in comments.

Comments

0

Afaik there is a discussion going on within the Symfony 2.0 dev guys in what places they should keep the "Bundles" extension.

I've just grabbed the latest version of Symfony via Git and followed your code 1:1.

I got various error messages too but when I changed...

  1. in src/Acme/StudyBundle/Resources/config/routing.yml

    defaults: { _controller: AcmeStudyBundle:Hello:index } to defaults: { _controller: AcmeStudy:Hello:index }

  2. app/config/routing.xml

    resource: "@AcmeStudyBundle/Resources/config/routing.yml" to resource: "@AcmeStudy/Resources/config/routing.yml"

...i got a pretty "Hello Ryan" in the browser.

Hope this helps!

1 Comment

This not worked for me. It seems they fiddle around with the releases.
0

You are probably running PR9. Update to PR11(latest), and I would bet this gets resolved. Symfony devs removed the 'Bundle' suffix in PR9, but added it back again shortly there after.

Also, Symfony devs keep an Update log that I find extremely helpful.

1 Comment

I am using PR11, so this should be no problem. But thanks for the link!

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.