【问题标题】:Fill Items to table from database using Prado Framework使用 Prado 框架将项目从数据库中填充到表中
【发布时间】:2012-09-07 10:43:03
【问题描述】:

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

还有我的 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】:

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

        <prop:ItemTemplate>
          <tr>
            <td><%#  $this->data->username %></>     
            <td><%#  $this->data->email %></>     
          </tr>
        </prop:ItemTemplate>
    

    【讨论】:

    • 谢谢。这件事奏效了..我已经使用了 TRepeater 一段时间,但后来我转向 TDataGrid..
    猜你喜欢
    • 1970-01-01
    • 2012-09-02
    • 2011-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多