首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Symfony CMS,命令规则:生成:实体不工作

Symfony CMS,命令规则:生成:实体不工作
EN

Stack Overflow用户
提问于 2015-10-13 16:23:57
回答 2查看 582关注 0票数 0

有问题吗?如何在Symfony CMS中为文档生成getter和setter?为什么命名空间TaskBundle或Acme\TaskBundle不能被命令规则识别:实体生成?

我已经安装了CMS的标准版,并尝试从官方文档中创建示例:http://symfony.com/doc/master/cmf/book/database_layer.html

我需要为文档Task.php生成setter和getter

为此,我决定使用命令“规则:生成:实体”。这样就创建了一个新的文件夹实体,并从Document folder: C:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition\src\Acme\TaskBundle\Entity\Task.php复制了Task.php文件。我希望生成setter和getter,然后将它们复制回Document\Task.php

命令规则:generate:entities不存在。因此,我更新了C:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition\composer.json comsposer.json

代码语言:javascript
复制
    "require": {
...
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",

但是现在我得到了关于命名空间的错误:

代码语言:javascript
复制
c:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition>php app/console generate:doctrine:entities TaskBundle:Task
  [Doctrine\ORM\ORMException]
  Unknown Entity namespace alias 'TaskBundle'.

c:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition>php app/console generate:doctrine:entity
The Entity shortcut name: Acme/TaskBundle:Task
Bundle "Acme\TaskBundle" does not exist.
The Entity shortcut name: TaskBundle:Task
Bundle "TaskBundle" does not exist.

C:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition\src\Acme\TaskBundle\Entity\Task.php

代码语言:javascript
复制
   <?php

    /* If you use annotations, you'll need 
     * to prepend all annotations with @PHPCR\, 
     * which is the name of the imported namespace 
     * (e.g. @PHPCR\Document(..)), 
     * this is not shown in Doctrine's documentation. 
     * You'll also need to include the 
     * use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
     *  statement to import the PHPCR annotations prefix. */


    // src/Acme/TaskBundle/Entity/Task.php
    namespace Acme\TaskBundle\Entity;

    class Task
    {
         /**
         * @PHPCR\Id()
         */
        protected $id;

        /**
         * @PHPCR\String()
         */
        protected $description;

        /**
         * @PHPCR\Boolean()
         */
        protected $done = false;

        /**
         * @PHPCR\ParentDocument()
         */
        protected $parentDocument;
    }



Questions?
How to generate getters and setters in Symfony CMS for documents?
Why namespace TaskBundle or Acme\TaskBundle is not recognised by the command doctrine:entities generate?
EN

回答 2

Stack Overflow用户

发布于 2015-10-13 17:41:00

另一种方法是编写自己的脚本来生成setter和getter。

文件示例(com.php)如下。在这种情况下,必须将字段名输入到自定义数组$avar中,并将正确的路径写入将生成setter和getter的文件。然后将文件保存到控制台所指向的目录(例如,c:\Bitnami\wampstack-5.4.38-0\symfony\project1\com.php)并运行命令行: c:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition>php com.php

代码语言:javascript
复制
<?php
//c:\Bitnami\wampstack-5.4.38-0\symfony\project1\com.php

//write here own field names, for which you need setters and getters
$avar=[ "description", "done", "parentDocument" ];
$sstr="<?php ";

foreach($avar as $item){
    $uitem=ucfirst($item);
        echo($item);

    $sstr=$sstr."

    /**
     * Set $item
     *
     * @param string \$$item
     *
     * @return **ADD**
     */
    public function set$uitem(\$$item)
    {
        \$this->$item = \$$item;

        return \$this;
    }

    /**
     * Get $item
     *
     * @return string
     */
    public function get$uitem()
    {
        return \$this->$item;
    }
    ";
 }   

//write here the path and filenae where setters and getters will be generated
// or you can append the file, where you need setters and getters
    $fcom=fopen("C:\Bitnami\wampstack-5.4.38-0symfony\project1\a.php","w");
    fwrite($fcom,$sstr);
    fclose($fcom);

//copy setter and getters to file, where you need them. 
票数 1
EN

Stack Overflow用户

发布于 2015-10-13 16:57:23

试试这个:

代码语言:javascript
复制
php app/console generate:doctrine:entities AcmeTaskBundle:Task
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33097646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档