A Symfony 5 controller is just a class. You could just use your IDE to create a new class for you, but you would need to add some boiler plate code like the namespace and then extend AbstractController and add some use statements etc.
Symfony 5+ has a better way though. With just one command you can have a new controller created with the basic boiler plate already created. How do you ask? With a simple Symfony maker command.
php bin/console make:controller NewControllerName
IT is that easy. Now you can go to the new Controller and start adding methods. Here is a deeper explanation.
This also creates a template. You can delete the template if you don’t need it or leave it. I got the following output when creating UserImageController
created: src/Controller/UserImageController.php created: templates/user_image/index.html.twig
You must log in to post a comment.