2

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 ) ?

4
  • 1
    You would better have separate bundles for frontend and backend. Commented Sep 24, 2014 at 11:28
  • 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 command Commented Sep 24, 2014 at 11:29
  • @moonwave99 could you explain why it's better to separate them please ? Commented Sep 24, 2014 at 12:50
  • 1
    @zizoujab because they have different purposes and they can be [re]used separately. Of course it is a matter of taste ^^ Commented Sep 25, 2014 at 9:49

3 Answers 3

4

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

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

1 Comment

Works in symfony 5.1 php 7.4
0

Like this (without template as well):

php bin/console make:controller Api\Cooking\Cooking --no-template 

1 Comment

Does that work for Symfony 2?
-1

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);
    ...
}

3 Comments

That will not answer the question... The link provided by the OP already list the options.
@Debflav Added details.
I'll try to add it and report back

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.