Symfony2 有一个用于生成控制器的命令
http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_controller.html
Command 的默认行为是在捆绑包内的
controller
文件夹内生成给定的控制器。
是否可以自定义生成控制器的文件夹(例如
controller/backend
)?
你可以尝试:“php bin/console make:controller Directory\ControllerName”
像这样(也没有模板): php bin/console make:controller Api\Cooking\Cooking --no-template
您可以通过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);
...
}