2014-04-24 6 views
1

내가 TableGateway의 select() 방법을 사용하여 MySQL의 테이블에 내가 가진 모든 내용을 표시하려고 :는 id 값을 검색 할 수 없습니다 젠드 TableGateway의 선택()

<section class="user_manager_index"> 
<h2>Users</h2> 
    <?php 
    $tableGateway = $this->tableGateway; 
    $rowset = $tableGateway->select(); 

    foreach ($rowset as $row) 
    { 
     echo $row->id . ' ' . $row->name . ' ' . $row->email . '<br>'; 
    } 
    ?> 
</section> 

을 그리고 테이블에서 모든 값을 반환 id 값을 제외하고는 괜찮지 만, $ row-> id의 값이 NULL과 같은 것은 쓰지 않는다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

추가 정보 : 내 TableGateway 공장 :

'UserTableGateway' => function($sm) 
    { 
     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); 
     $resultSetPrototype = new ResultSet(); 
     $resultSetPrototype->setArrayObjectPrototype(new User()); 
     return new TableGateway('user', $dbAdapter, null, $resultSetPrototype); 
    } 

추가 정보 : 내 사용자 클래스 : exchangeArray 방법은 데시벨 값으로 속성을 채우는 데 사용되는

class User 
{ 
    public $id; 
    public $name; 
    public $email; 
    public $password; 

    public function setPassword($clear_password) 
    { 
     $this->password = md5($clear_password); 
    } 
    public function exchangeArray($data) 
    { 
     $this->name = (isset($data['name'])) ? 
     $data['name'] : null; 
     $this->email = (isset($data['email'])) ? 
     $data['email'] : null; 
     if (isset($data['password'])) 
     { 
      $this->setPassword($data['password']); 
     } 
    } 
} 

답변

2

귀하의 User 클래스는 현재 아무튼 ' id을 참조하십시오.

public function exchangeArray($data) 
{ 
    // populate the id 
    $this->id = isset($data['id']) ? $data['id'] : null; 

    $this->name = (isset($data['name'])) ? 
    $data['name'] : null; 
    $this->email = (isset($data['email'])) ? 
    $data['email'] : null; 
    if (isset($data['password'])) 
    { 
     $this->setPassword($data['password']); 
    } 
} 
+0

고맙습니다. 코드 스 니펫에 표시된대로 클래스 사용자를 변경 했으므로 이제 내보기의 $ row-> id는 id 값을 반환합니다. – user3533043