Php Can';使用Zend TableGateway';s select()
我尝试使用TableGateway的Php Can';使用Zend TableGateway';s select(),php,mysql,zend-framework,zend-framework2,tablegateway,Php,Mysql,Zend Framework,Zend Framework2,Tablegateway,我尝试使用TableGateway的select()方法显示MySql表中的所有内容: <section class="user_manager_index"> <h2>Users</h2> <?php $tableGateway = $this->tableGateway; $rowset = $tableGateway->select(); foreach ($rowset as $row) {
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>
其他信息:我的用户类:
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']);
}
}
}
您的
User
classexchangeArray
方法用于用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']);
}
}
非常感谢,正如您在代码片段中所示,我已经更改了类用户,现在我视图中的$row->id返回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']);
}
}