我在我的表中有下劃線字段像display_name我使用ClassMethod hydrator轉換下劃線到駱駝案件,但它不起作用,(電子郵件屬性工作,但displayName不起作用)這是我的代碼:Zendramework 2 ClassMethod Hydrator
class UserEntity
{
protected $email;
protected $displayName;
public function getDisplayName()
{
return $this->displayName;
}
public function setDisplayName($displayName)
{
$this->displayName = $displayName;
return $this;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
}
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$UserEntity = new \UserManagement\Model\UserEntity;
$hydrator = new \Zend\Stdlib\Hydrator\ClassMethods;
$resultSet = new \Zend\Db\ResultSet\HydratingResultSet($hydrator,$UserEntity);
$tableGateway = new \Zend\Db\TableGateway\TableGateway('user',$dbAdapter,null,$resultSet);
$table = new \UserManagement\Model\UserTable($tableGateway);
請別人幫我 – Dante
如果水化器不工作,你想你可以做一個自己的方式,只是執行'Zend \ Stdlib \ Hydrator \ HydratorInterface'我有類方法的麻煩,因爲我的實體從一個抽象的實體擴展,並有幾個父類中的類,我不想被水合 – SmasherHell