使用Prado Framework将项目从数据库填充到表中

问题描述 投票:0回答:1

我是prado的新手,我遇到了如何填充这个问题的问题。到目前为止,这就是我所做的:

home.怕个:

    <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>

和我的Home.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();
                    }
                }           
            }
            ?>

我已经与我的数据库建立了连接。那么,如何用我的数据库中的项目填写表格?

php html-table prado
1个回答
2
投票

假设getListTest()返回一个正确的记录数组(var_dump它要检查),你只需要引用转发器的$ this-> data。范围是转发器。所以$ this是转发器对象的别名。当转发器遍历您的阵列时,它会将$ this->数据更改为当前记录。

    <prop:ItemTemplate>
      <tr>
        <td><%#  $this->data->username %></>     
        <td><%#  $this->data->email %></>     
      </tr>
    </prop:ItemTemplate>
© www.soinside.com 2019 - 2024. All rights reserved.