3

I am studying right now the Symfony 4. I am trying to familiarize myself to this framework. For example in Laravel there's php artisan make:controller PhotoController..

NOTE: I tried

php app/console generate:controller or
php app/console generate:controller <name>

It gives me an error

Could not open input file: app/console

When I tried this

php bin/console generate:controller or php bin/console generate:controller <name>

It gives me an error "There are no commands defined in the generate namespace"

Question: Is there any command that will create a controller with method so that I wont type any more

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;  
6
  • that is php bin/console generate:controller for generate controller not app/console Commented Jan 3, 2018 at 8:46
  • Actually I tried it also but it gives me also an error "There are no commands defined in the generate namespace" Commented Jan 3, 2018 at 8:49
  • use which version of symfony? Commented Jan 3, 2018 at 8:50
  • are sure you are in the root of the symfony project? this error occur when php cant find console Commented Jan 3, 2018 at 8:51
  • I didnt specify the version of my app. I think it's the default? Because I just followed the instruction given. composer create-project symfony/skeleton symfony Commented Jan 3, 2018 at 8:52

4 Answers 4

10

There is such command, instead of SymfonyGeneratorBundle use MakerBundle for Symfony 3.4/4.0 now, Generator is deprecated and as I know not maintained anymore, basic usage:

bin/console make:controller

More here

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

2 Comments

I downloaded the file of maker bundle.... in the github (github.com/symfony/maker-bundle) where should I put those files
You don't need to "download" them, just use composer command and Flex will automatically add dependencies for your project: composer require symfony/maker-bundle See list of available projects for Flex here: symfony.sh
2

Instead of

app/console

try

php app/console

here is doc Generating a New Controller

1 Comment

you are using symfony4, so I think there is no option to generate a controller yet
1

For generation controller bin/console generate:controller, you need to have installed sensio/generator-bundle, but as I know it doesn't work with Symfony 4 now. Try to use bin/console for getting available commands.

2 Comments

I just checked it, it doesnt have any generate:controller.
Sure, because this bundle does not support Symfony 4. It also does not support the new bundle-less directory structure as created by Symfony Flex. Use the Maker bundle instead. github.com/symfony/maker-bundle and Symfony docs: symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html
-1

There are two ways to create a new controller in Symfony

1 php bin/console make:controller UserController

2 symfony console make:controller UserController

1 Comment

Please add some explanation to your answer such that others can learn from it. Is there any difference between this answer and the one by Generwp posted five years ago?

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.