2013-03-03 74 views
0

我想根據數據庫表格記錄建立一個動態表格。Zend_Form從數據庫表格行中顯示錶格

這是一個房間預訂模塊。

酒店有幾個房間類型的描述。 當預訂酒店的用戶應該看到格式如:

-- firstname [text-input] 
    -- lastname [text-input] 
    -- check-in [text-input and datepicker] 
    -- check-out [text-input and datepicker] 
    -- Room1 Title:Room Description [Text-input form for number of rooms] 
    -- Room2 Title:Room Description [Text-input form for number of rooms] 
    -- Room3 Title:Room Description [Text-input form for number of rooms] 
    -- Room4 Title:Room Description [Text-input form for number of rooms] 

我有一個表這個房間的記錄。 如何使用ZEND_FORM構建這個? 我認爲它應該像房間的對象foreach

我也想添加自動計算。 每間客房每晚都有特定的價格。 我想總結房間的數量並乘以夜晚的數量。

那麼我該如何使用Zend_Form來完成它? 我應該添加一些助手嗎?新的文本元素類型?

如果是,請提供一些資料來指導和如何使用示例。

預先感謝您。

回答

1

我有類似的東西,但有複選框,這是一個適應,我希望它有幫助。

class Form_Booking extends Zend_Form { 
    function init() 
    { 
     $this->addElement('text', 'first_name', array (
      'label' => 'First name', 
      'required' => true 
     )); 

     // ... all the other fields 

     $count = 1000; // I used this value because I had a strange bug 
     //$rooms = array() the entries from your table 
     foreach ($rooms as $one) 
     {  
      $this->addElement('checkbox', "$count", array (
       'label'   => $one['room_title'], 
       'description' => $one['room_description'], 
       'belongsTo'  => 'rooms', 
     )); 
      $count++; 
     } 
    } 
} 
+0

我需要在我的窗體中獲取一個GET變量,以在我的init()函數中從DB生成SELECT。如何將index.php中的hotel_id傳遞給from.php? – mrGott 2013-03-07 11:42:49

+0

使用[這個答案](http://stackoverflow.com/questions/3863083/pass-variable-into-zend-form)關於如何將變量傳遞給zend窗體。 – 2013-03-11 06:57:06