有问题吗? 如何在Symfony CMS中为文档生成getter和setter? 为什么命令doctrine无法识别命名空间TaskBundle或Acme \ TaskBundle:实体生成?
我已安装CMS的标准版,并尝试从官方文档中提供示例: http://symfony.com/doc/master/cmf/book/database_layer.html
我需要为Document Task.php生成setter和getter
为此,我决定使用命令" doctrine:generate:entities"。从而创建了一个新文件夹Entities并从Document文件夹中复制了Task.php文件: C:\ Bitnami \ wampstack-5.4.38-0 \ sym_prog \标准版的\ src \ Acme的\ TaskBundle \实体\ Task.php 我希望生成setter和getter,然后将它们复制回Document \ Task.php
命令原则:generate:实体不存在。 因此我更新了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?
答案 0 :(得分:1)
另一种方法是为setter和getters生成编写自己的脚本。
文件示例(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&gt; 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.
答案 1 :(得分:0)
试试这个:
set agentName = Node.selectSingleNode("AgentName")
If Not agentName Is Nothing Then
response.write agentName.text
End If