问题?如何在Symfony CMS中为文档生成getter和setter?为什么命名空间 TaskBundle 或 Acme''TaskBundle 不被命令原则:实体生成识别?
我已经安装了CMS的标准版,并尝试从官方文档中举例:http://symfony.com/doc/master/cmf/book/database_layer.html
我需要为文档任务生成资源库和获取器.php
为此,我决定使用命令"doctrine:generate:entities"。因此创建了一个新文件夹实体并从文档文件夹中复制了任务.php文件:C:''Bitnami''wampstack-5.4.38-0''sym_prog''standard-edition''src''Acme''TaskBundle''Entity''Task.php我希望生成资源库和获取器,然后将它们复制回文档''任务.php
命令原则:生成:实体不存在。因此,我更新了comsposer.jsonC:''Bitnami''wampstack-5.4.38-0''sym_prog''standard-edition''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''standard-edition''src''Acme''TaskBundle''Entity''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?
另一种方法是为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
<?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.
试试这个:
php app/console generate:doctrine:entities AcmeTaskBundle:Task