2013-03-03 71 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