2012-09-14 30 views
0

我是新來的普拉多,我在如何將這個填充到我的表中有問題。到目前爲止,這是我做了什麼:使用Prado Framework從數據庫中填充項目

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> 

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

我已經建立我的數據庫連接。 那麼,我該如何填寫我的數據庫中的項目?

回答

2

假設getListTest()返回一個合適的記錄數組(var_dump它來檢查),你只需要引用中繼器的$ this-> data。範圍是中繼器。所以$這是中繼器對象的別名。當中繼器遍歷數組時,它會將$ this-> data更改爲當前記錄。

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

謝謝。這件事情的工作..我已經使用TRepeater一段時間,但後來我轉移到TDataGrid .. – lawrence