문제

I'm new to prado and I'm having a problem on how to populate this to my table. So far, this is what I have done:

Home.page:

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

and my 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();
                    }
                }           
            }
            ?>

I have already establish connection with my database. So, how can I fill in my table with the items from my database?

도움이 되었습니까?

해결책

Assuming that getListTest() is returning a proper array of records (var_dump it to check) you only need to reference $this->data of the repeater. scope is the repeater. So $this is an alias to the repeater object. As the repeater iterates through your array it will change the $this->data to the current record.

    <prop:ItemTemplate>
      <tr>
        <td><%#  $this->data->username %></>     
        <td><%#  $this->data->email %></>     
      </tr>
    </prop:ItemTemplate>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top