1

TableGateway のselect()メソッドを使用して、MySql テーブルにあるすべてのコンテンツを表示しようとしています。

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

追加情報: 私のユーザー クラス:

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']);
        }
    }
}
4

1 に答える 1

2

あなたのUserクラスexchangeArrayメソッドは、プロパティに db 値を入力するために使用されます。現在、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']);
    }
}
于 2014-04-24T22:39:25.507 に答える