Symfony2 在自定义文件夹中生成控制器

问题描述 投票:0回答:3

Symfony2 有一个用于生成控制器的命令

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

Command 的默认行为是在捆绑包内的

controller
文件夹内生成给定的控制器。

是否可以自定义生成控制器的文件夹(例如

controller/backend
)?

php symfony command-line
3个回答
3
投票

你可以尝试:“php bin/console make:controller Directory\ControllerName”


0
投票

像这样(也没有模板): php bin/console make:controller Api\Cooking\Cooking --no-template


-1
投票

您可以通过help命令获取该命令的所有可用选项:

php app/console help generate:controller

不,您不能执行当前任务,但您可以扩展

GenerateControllerCommand
以添加自定义选项。看看它的
generate
功能:

// 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);
    ...
}
© www.soinside.com 2019 - 2024. All rights reserved.