문제

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