有問題? 如何在Symfony CMS中爲文檔生成getter和setter? 爲什麼命名空間TaskBundle或Acme \ TaskBundle不被命令doctrine識別:實體生成?Symfony CMS,命令學說:生成:實體不起作用
我已經安裝了CMS的標準版,並設法使從官方文檔的例子: http://symfony.com/doc/master/cmf/book/database_layer.html
我需要生成文檔Task.php
爲此,我決定getter和setter方法使用命令「doctrine:generate:entities」。因此,從創建Document文件夾的新文件夾實體和複製Task.php文件: C:\ Bitnami \ wampstack-5.4.38-0 \ sym_prog \標準版的\ src \ Acme的\ TaskBundle \實體\ Task.php 我希望生成getter和setter方法,比複製回他們的文檔\ Task.php
命令主義:生成:實體是不存在的。 因此我更新comsposer.json C:\ Bitnami \ wampstack-5.4.38-0 \ sym_prog \標準版\ composer.json
"require": {
...
"doctrine/orm": "^2.4.8",
"doctrine/doctrine-bundle": "~1.4",
但現在我得到有關命名空間中的錯誤:
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 \標準版的\ src \ Acme的\ TaskBundle \實體\ Task.php
<?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?
謝謝。使用你的命令我仍然收到錯誤:[RuntimeException] Bundle「AcmeTaskBundle」不包含任何映射實體。 – olga
您是否在任務實體中添加了名稱空間? – Soufiene
我編輯了問題並粘貼了整個Task.php文件。它具有命名空間Acme \ TaskBundle \ Entity; – olga