Search code examples
zend-framework2class-method

Zendramework 2 ClassMethod Hydrator


I have underscore fields in my table like display_name I use ClassMethod hydrator to convert underscore to camel case but It doesn't work , (email property works but displayName doesn't work) this is my code :

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);

Solution

  • Are you sure all of your database fields have data ? Maybe they are empty and simply it doesn't return any valud