Вопрос

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);
Это было полезно?

Решение

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

Другие советы

Instead of writing your own hydrator, you could create a new Naming Strategy and assign it to the hydrator. The ClassMethods hydrator, by default, uses the Zend\Stdlib\Hydrator\NamingStrategy\UnderscoreNamingStrategy. You could examine the code in the strategy, and make the appropriate changes, creating your own custom naming strategy. Make sure you also create an interface to match it.

You would then need to remove the UnderscoreNamingStrategy, and add your own custom one as follows:

$hydrator = new ClassMethods();
$hydrator->removeNamingStrategy('UnderscoreNamingStrategy');
$hydrator->addStrategy('CustomStrategy', 'CustomStrategyInterface');
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top