0

I'm trying a school project in Symfony but I'm getting an error that stopped me for several hours, I couldn't find any answer so I hope someone of you can help me.

I'm trying to set a view for a user registration with a form, I've follow some Symfony cookbook guides but couldn't reach to the end.

I'll put you on situation, I have a bundle with the default controller where I have put by now all functions that render a view, but I want to do it better and to have various controllers to have a better organization.

I've created a controller called: AccountControler.php which is in // src/AppBundle/Controller/AccountController.php

     <?php
    // src/AppBundle/Controller/AccountController.php
    namespace AdrianG\RegisterBundle\Controller;
    
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use AdrianG\RegisterBundle\Form\UserType;
    use AdrianG\RegisterBundle\Entity\User;
    use Symfony\Component\HttpFoundation\Request;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    
    class RegistrationController extends Controller
    {
        /**
         * @Route("/register", name="user_registration")
         */
        public function registerAction(Request $request)
        {
//....

I think the routing is correct:

user_registration:
    pattern:  /register
    defaults: { _controller: AdrianGRegisterBundle:Account:register}

and I'm getting an error when trying to access

localhost/symfony8/web/app_dev.php/user/register

The autoloader expected class "AdrianG\RegisterBundle\Controller\AccountController" to be defined in file "/Applications/AMPPS/www/symfony8/src/AdrianG/RegisterBundle/Controller/AccountController.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

I'm able to access to anywhere with my routes and with DefaultController.php I 've search and people says about namespace ( ¿I think its correct no? ) or about <? that should be <?php

I really don't know what can be the problem and some help would be really nice

EDIT: DefaultController.php and AccountControler.php are in the same folder, and they have the same namespace, should it be so?

2
  • The file is called AccountController.php, but the class inside it is called RegistrationController. You should follow PSR-4 and name the class too: "AccountController" Commented Dec 11, 2015 at 16:56
  • okok, ill try that solution, what a fast response ( i just copied the names from the symfony cookbook) symfony.com/doc/current/cookbook/doctrine/… Commented Dec 11, 2015 at 16:59

1 Answer 1

2

You have got your routing wrong.
It should be;

user_registration:
    pattern:  /register
    defaults: { _controller: AdrianGRegisterBundle:Registration:register}

The filename of the class should also be RegistrationController.php

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

3 Comments

Perfect solution, thanks, thanks to both of you, i think that symfony should correct it from his page
Which page were you following? You have the route defined in a routing file as well as an annotation. I suspect you are mixing up two different pieces of documentation.
this one symfony.com/doc/current/cookbook/doctrine/… Im for sure mixing different pieces of documentation, i think somewhere in the documentation said that i can use one of them, just to many copy/paste and I forgot to delte that because im used to see those lines as commentarys, not as programing code, thanks for the "tip"

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.