我是prado的新手,在如何将其填充到表中时遇到了问题。到目前为止,这就是我所做的:
主页.页面:
<com:TForm>
<com:TRepeater ID="test">
<prop:HeaderTemplate>
<table class="list" border="1px" borderWidth="1px" borderColor="#CCCCCC" style="margin-top: 30px;">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</prop:HeaderTemplate>
<prop:ItemTemplate>
<tr>
<td><%# xxxxxxxx%></> <!--this is the part where i will put my... -->
<td><%# xxxxxxxxxx%></> <!--...data from database -->
</tr>
</prop:ItemTemplate>
</com:TRepeater>
</com:TForm>
和我的家.php:
<?php
class Home extends TPage
{
protected function getListTest()
{
// Returns an array containing all the records from the table
return TestRecord::finder()->findAll();
}
public function onLoad($param)
{
if (!$this->IsPostBack)
{
// Populate the Test Drop Down from database values
$this->test->DataKeyField = 'username';
$this->test->DataKeyField = 'email';
$this->test->DataSource = $this->ListTest;
$this->test->dataBind();
}
}
}
?>
我已经和我的数据库建立了连接。那么,我如何用数据库中的项目来填充我的表呢?
假设getListTest()返回一个正确的记录数组(var_dump it to check),您只需要引用中继器的$this->数据。范围是中继器。所以$this是repeater对象的别名。当中继器在数组中迭代时,它将把$this->数据更改为当前记录。
<prop:ItemTemplate>
<tr>
<td><%# $this->data->username %></>
<td><%# $this->data->email %></>
</tr>
</prop:ItemTemplate>