0
我正在尋找關於創建動態表單的設計思路。動態表單構建/元編程/ PHP
什麼我現在已經是例如一些屬性/變量一堆型號:
class Group extends IDKModel {
/**
* @Form
*/
public $title;
/**
* @Form(validation="{my validation rules here}")
*/
public $permissions;
}
在該示例窗體PHPAnnotation把它定義爲一個表單元素和驗證陣列將內置的驗證規則。現在我遇到的問題是我不知道如何實現條件。
例如,如果僅當用戶是管理員時才顯示$權限。如果時間是格林尼治標準時間12:00以後,如何顯示$ title。基本上任何一種有條件的。
在irc.quakenet.org從#PHP摘自:
[10:50] <ramirez> i would not try to stick all of the meta-info under one attribute
[10:50] <ramirez> it'd be much cleaner to do something like
[10:50] <ramirez> @FormElement
[10:51] <ramirez> @Validator(params)
[10:51] <ramirez> etc
[10:52] <ramirez> anyways, I would probably do something like.. @Filter(name="Group",value="admin,editor")
[10:53] <ramirez> then for each filter you want to implement, you'll create a class like "Model_Filter_Group", which would be used for eg. the above filter
[10:53] <ramirez> that class in this case would simply explode the groups by comma and see if user is in any of those groups
[10:54] <ramirez> you can use that for any kind of filtering, eg: @Filter(name="PastTime", value="12:00")
任何人都有一個簡單的想法?
上發現一個教程,儘量不要與驗證邏輯混合形式表示邏輯。這不是一個簡單的問題,但我確實有一個解決方案。它只是相當大,我不知道在哪裏發佈。 – Petah 2011-02-03 08:55:13