【问题标题】:How to generate `getter/setter` for ZF2 and Doctrine using a command line tool?如何使用命令行工具为 ZF2 和 Doctrine 生成`getter/setter`?
【发布时间】:2014-03-05 18:10:16
【问题描述】:

如何使用命令行工具为 ZF2 和 Doctrine 生成 getter/setter?像 $myEntity->getUsername() 和 $myEntity->setUsername('foo'); 我正在使用它来生成实体:

./vendor/bin/doctrine-module orm:convert-mapping --force --from-database annotation ./Entity/

【问题讨论】:

    标签: php doctrine-orm zend-framework2 doctrine


    【解决方案1】:

    我使用这个脚本http://mostafa.info/~NKIBl0 它对我真的很有帮助。像这样使用它:

    php generateGettersAndSetters.php file.php > generatedFile.php
    

    【讨论】:

    • 感谢穆斯塔法!它完美无缺。 (请注意:总有一天我会后悔执行我在 stackoverflow 上看到的命令行指令)。
    【解决方案2】:

    您无需使用第 3 方脚本,因为您使用的是 DoctrineORMModule。 Doctrine 原生的ConvertMapping 命令已经为我们提供了所需的选项。

    您只需将true 作为generate-methods 参数值传递给CLI,如下所示:

    $ cd /path/to/your/project
    $ php public/index.php orm:convert-mapping --from-database annotation ./Entity/ --update-entities="true" --generate-methods="true"
    

    【讨论】:

      猜你喜欢
      • 2014-11-12
      • 2015-03-22
      • 1970-01-01
      • 2014-11-25
      • 2021-10-28
      • 2018-11-30
      • 1970-01-01
      • 2014-09-03
      • 1970-01-01
      相关资源
      最近更新 更多