Symfony2.4.1 - 在一个命令中生成带有操作的控制器失败

时间:2014-02-07 23:25:04

标签: symfony

我想用一堆动作生成一个控制器,但只使用一个命令。

我使用的命令:

$ php app/console generate:controller --no-interaction --controller=Sample01DemoBundle:Demo1 --actions=helloAction:/hello:Sample01DemoBundle:Demo1:hello.html.twig --route-format=yml --template-format=twig

这是错误输出:

  Controller generation  


PHP Warning:  Illegal string offset 'name' in /home/rocker/projects/sample01/vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Generator/ControllerGenerator.php on line 56
PHP Warning:  Illegal string offset 'basename' in /home/rocker/projects/sample01/vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Generator/ControllerGenerator.php on line 56
PHP Warning:  Illegal string offset 'template' in /home/rocker/projects/sample01/vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Generator/ControllerGenerator.php on line 61
PHP Notice:  Undefined offset: 2 in /home/rocker/projects/sample01/vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Generator/ControllerGenerator.php on line 190
PHP Notice:  Undefined offset: 1 in /home/rocker/projects/sample01/vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Generator/ControllerGenerator.php on line 190



  [Twig_Error_Runtime]                                                                                         
  Impossible to access an attribute ("basename") on a string variable ("elloAction:/hello/{id}:Sample01DemoB  
  undle:Demo1:hello.html.twig") in "controller/Template.html.twig.twig" at line 4 

其他信息:

$ php app/console --version
Symfony version 2.4.1 - app/dev/debug

我做错了什么? 捆绑生成工作正常。

每个想法都得到了解释。感谢。

1 个答案:

答案 0 :(得分:2)

对actions参数使用引号:

--actions="helloAction:/hello:Sample01DemoBundle:Demo1:hello.html.twig"

另见:

Generating a New Controller

<强> UPD:

根据SensioGeneratorBundle github,控制器生成器仅在symfony版本 2.2.x 后可用。因此,如果要使用控制器生成器,则必须更新symfony副本。