我使用Zend Framework 1与Bisna库集成了Doctrine 2.我使用Doctrine 2 CLI从我的数据库模型生成了我的实体。除了关联记录的setter方法外,这一切都正常工作。他们接受的参数必须是特定的命名空间(这里的\Category
)。Doctrine 2命名空间问题
class Article
{
public function setCategory(\Category $category = null) {
$this->category = $category;
return $this;
}
}
然而,当我这样做:
$article = $this->em->getRepository('\Application\Entity\Article')->find(1);
$category = new \Application\Entity\Category();
$category->SetName('New Category');
$article->setCategory($category);
我得到以下致命错误:Argument 1 passed to Application\Entity\CategoryField::setCategory() must be an instance of Category, instance of Application\Entity\Category given
。
当我改变setter方法来接受\Application\Entity\Category
对象时,它当然在工作。我应该为每个生成的方法执行此操作,还是有其他选项?这是我第一次使用名称空间,所以它可能很简单。更多信息有关use
http://php.net/manual/en/language.namespaces.importing.php否则,你就必须: