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