symfony2 error: [RuntimeException] Namespace "ProjectBundle\Entity\Mandator" does not contain any mapped entit ies
symfony2 error: [RuntimeException] Namespace "ProjectBundle\Entity\Mandator" does not contain any mapped entit ies
我在 Symfony2 的 OneToMany 关系中遇到问题。我创建了实体
委托人
// src/Pso/ProjectBundle/Entity/Mandator.php
namespace Pso\ProjectBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="mandator", options={"collate"="utf8_general_ci",
"charset"="utf8", "engine"="InnoDB"})
* @ORM\Entity()
*/
class Mandator
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="Pso\ProjectBundle\Entity\Project",
mappedBy="mandator")
*/
private $projects;
/**
* @ORM\Column(type="string", length=50, nullable=false)
*/
private $longname;
/**
* @ORM\Column(type="string", length=50, nullable=false)
*/
private $shortname;
public function __construct() {
$this->projects = new ArrayCollection();
}
}
和实体 Project,wgich 与另一个名为 User
的实体有关系
// src/Pso/ProjectBundle/Entity/Project.php
namespace Pso\ProjectBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="project", options={"collate"="utf8_general_ci",
"charset"="utf8", "engine"="InnoDB"})
* @ORM\Entity(repositoryClass="Pso\ProjectBundle\Entity\ProjectRepository")
* @ORM\Entity()
*/
class Project
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, unique=true, nullable=false)
*/
private $project_nr;
/**
* @ORM\ManyToOne(targetEntity="Pso\ProjectBundle\Entity\Mandator",
inversedBy="projects")
* @ORM\JoinColumn(name="mandator_id", referencedColumnName="id")
*/
private $mandator;
/**
* @ORM\Column(type="string", length=80, nullable=false)
*/
private $project_name;
/**
* @ORM\Column(type="string", length=50)
*/
private $customer;
/**
* @ORM\Column(type="string", length=50)
*/
private $label;
/**
* @ORM\Column(type="date")
*/
private $shipping_date;
/**
* @ORM\Column(type="float")
*/
private $advance_payment;
/**
* @ORM\Column(type="integer", length=1)
*/
private $probability;
/**
* @ORM\Column(type="blob")
*/
private $special_demand;
/**
* @ORM\Column(type="string", length=4)
*/
private $currency;
/**
* @ORM\Column(type="integer", length=1, nullable=false)
*/
private $status;
/**
* @ORM\Column(type="string", length=100)
*/
private $contract_nr;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $dbinsert;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $dbupdate;
/**
* @ORM\ManyToMany(targetEntity="Pso\LogBundle\Entity\User", cascade=
{"persist", "remove"})
*/
private $users;
public function __construct() {
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
}
}
当我现在尝试使用命令生成 setter 和 getter 时
app/console doctrine:generate:entities ProjectBundle/Entity/Mandator
或
app/console doctrine:generate:entities ProjectBundle/Entity/Project
我收到错误
[RuntimeException]
Namespace "ProjectBundle\Entity\Mandator" does not contain any mapped
entities.
我读了几个主题,例如 (topic 1, topic2, topic 3),但不知道我的错误可能在哪里。
您似乎忘记了命名空间的根部分 'Pso'。
你必须执行:
app/console doctrine:generate:entities Pso/ProjectBundle/Entity/Mandator
我在 Symfony2 的 OneToMany 关系中遇到问题。我创建了实体
委托人
// src/Pso/ProjectBundle/Entity/Mandator.php
namespace Pso\ProjectBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="mandator", options={"collate"="utf8_general_ci",
"charset"="utf8", "engine"="InnoDB"})
* @ORM\Entity()
*/
class Mandator
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="Pso\ProjectBundle\Entity\Project",
mappedBy="mandator")
*/
private $projects;
/**
* @ORM\Column(type="string", length=50, nullable=false)
*/
private $longname;
/**
* @ORM\Column(type="string", length=50, nullable=false)
*/
private $shortname;
public function __construct() {
$this->projects = new ArrayCollection();
}
}
和实体 Project,wgich 与另一个名为 User
的实体有关系// src/Pso/ProjectBundle/Entity/Project.php
namespace Pso\ProjectBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="project", options={"collate"="utf8_general_ci",
"charset"="utf8", "engine"="InnoDB"})
* @ORM\Entity(repositoryClass="Pso\ProjectBundle\Entity\ProjectRepository")
* @ORM\Entity()
*/
class Project
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, unique=true, nullable=false)
*/
private $project_nr;
/**
* @ORM\ManyToOne(targetEntity="Pso\ProjectBundle\Entity\Mandator",
inversedBy="projects")
* @ORM\JoinColumn(name="mandator_id", referencedColumnName="id")
*/
private $mandator;
/**
* @ORM\Column(type="string", length=80, nullable=false)
*/
private $project_name;
/**
* @ORM\Column(type="string", length=50)
*/
private $customer;
/**
* @ORM\Column(type="string", length=50)
*/
private $label;
/**
* @ORM\Column(type="date")
*/
private $shipping_date;
/**
* @ORM\Column(type="float")
*/
private $advance_payment;
/**
* @ORM\Column(type="integer", length=1)
*/
private $probability;
/**
* @ORM\Column(type="blob")
*/
private $special_demand;
/**
* @ORM\Column(type="string", length=4)
*/
private $currency;
/**
* @ORM\Column(type="integer", length=1, nullable=false)
*/
private $status;
/**
* @ORM\Column(type="string", length=100)
*/
private $contract_nr;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $dbinsert;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $dbupdate;
/**
* @ORM\ManyToMany(targetEntity="Pso\LogBundle\Entity\User", cascade=
{"persist", "remove"})
*/
private $users;
public function __construct() {
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
}
}
当我现在尝试使用命令生成 setter 和 getter 时
app/console doctrine:generate:entities ProjectBundle/Entity/Mandator
或
app/console doctrine:generate:entities ProjectBundle/Entity/Project
我收到错误
[RuntimeException] Namespace "ProjectBundle\Entity\Mandator" does not contain any mapped
entities.
我读了几个主题,例如 (topic 1, topic2, topic 3),但不知道我的错误可能在哪里。
您似乎忘记了命名空间的根部分 'Pso'。
你必须执行:
app/console doctrine:generate:entities Pso/ProjectBundle/Entity/Mandator