我使用zf2.1.3和doctrine 2.我试图在我的课程上提供信息,并意识到DoctrineModule\Stdlib\Hydrator\DoctrineObject
不适用于带有下划线的字段,如cat_id
。Doctrine 2 Hydrator - 带下划线的字段
下面的例子:
/* namespace Application\Entity; */
class Foo
{
private $cat_id;
private $cat_name;
public function getCatId()
{
return $this->cat_id;
}
public function setCatName($name)
{
$this->cat_name = $name;
return $this;
}
public function getCatName()
{
return $this->cat_nome;
}
}
class Bar
{
private $id;
private $name;
public function getId()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->nome;
}
}
/* namespace Application\Controller; */
use \DoctrineModule\Stdlib\Hydrator\DoctrineObject;
public function indexAction()
{
$hydrator = new DoctrineObject($this->getEntityManager(), 'Application\Entity\Foo');
$foo = $hydrator->hydrate(array('cat_name' => 'Frank Moraes'), new Foo());
\Zend\Debug\Debug::dump($foo, 'Foo Hydrator');
$hydrator = new DoctrineObject($this->getEntityManager(), 'Application\Entity\Bar');
$bar = $hydrator->hydrate(array('name' => 'Frank Moraes'), new Bar());
\Zend\Debug\Debug::dump($inscrit, 'Bar Hydrator');
}
此代码返回如下:
Foo Hydrator
object(Application\Entity\Foo)
private 'cat_id' => null
private 'cat_name' => null
Bar Hydrator
object(Application\Entity\Foo)
private 'id' => null
private 'name' => 'Frank Moraes'
所以我的问题是:为什么主义保湿不与在它强调的领域工作? 我该如何做这项工作?
谢谢!
编辑
很抱歉的很长一段时间没有答案。在我的工作中,没有人可以访问!
我试过如下:
$hydrator = new DoctrineObject($this->getEntityManager(), 'Application\Entity\Foo', false);
对于我贴在这里,这false
参数正常工作的例子。
但是,当我绑定表单上的类时,它不起作用!
有人有线索吗?
我会发布此问题上的原则谷歌的用户群。 – 2013-03-11 01:31:45
这是因为默认的inflector不处理下划线。您需要自行调整它或在https://github.com/doctrine/DoctrineModule/issues上发布关于Doctrine模块问题跟踪器的问题 我现在可以告诉您,我没有时间查看虽然现在进入它。 – Ocramius 2013-03-11 03:05:22
我在https://github.com/doctrine/DoctrineModule/issues/190上发布了这个问题 – vinigarcia87 2013-03-13 01:14:21