2
votes

Symfony2 has a command for generating controllers

http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_controller.html

Command's default behavior is to generate the given controller inside controller folder within the bundle.

Is it possible to customize the folder where the controller will be generated ( controller/backend for example ) ?

2
You would better have separate bundles for frontend and backend.moonwave99
I don't think that you can add the subfolder in the command. Moreover I don't think it's a good way to add a subdirectory in the YourBundle\Controller. By the way, may you want create your own generate:controller. Have a look at How to create a basic commandDebflav
@moonwave99 could you explain why it's better to separate them please ?zizoujab
@zizoujab because they have different purposes and they can be [re]used separately. Of course it is a matter of taste ^^moonwave99

2 Answers

-1
votes

You can get all the available options of this command with the help command:

php app/console help generate:controller

No you can't with the current task, but you could extend the GenerateControllerCommand to add custom options. Check out its generate function:

// GenerateControllerCommand.php
public function generate(BundleInterface $bundle, $controller, $routeFormat, $templateFormat, array $actions = array())
{
    ...
    $controllerFile = $dir.'/Controller/'.$controller.'Controller.php';
    ...
    $this->renderFile('controller/Controller.php.twig', $controllerFile, $parameters);
    ...
}
2
votes

You can try: "php bin/console make:controller Directory\\ControllerName"