setPluginLoader($loader, $type):
$loader はプラグインローダーオブジェクトで、type
は先ほど説明した型のいずれかです。
これは、指定した型のプラグインローダーを
指定したローダーオブジェクトに設定します。
getPluginLoader($type):
$type に関連づけられたプラグインローダーを取得します。
addPrefixPath($prefix, $path, $type = null):
プレフィックスとパスの関連づけを、$type で指定したローダーに指定します。
$type が null の場合はそのパスをすべてのローダーに追加します。この場合、
プレフィックスの後に "_Element" および
"_Decorator" を追加し、パスに "Element/" および
"Decorator/" を追加します。追加のフォーム要素クラス群をすべて同じ階層に配置した場合は、
このメソッドを使用すると簡単に基底プレフィックスを設定することができます。
addPrefixPaths(array $spec):
複数のパスを、ひとつあるは複数のプラグインローダーに一度に追加します。
配列の各要素は、キー 'path'、'prefix' および
'type' を持つ配列となります。
addElementPrefixPath($prefix, $path, $type = null):
addPrefixPath() と同じですが、
クラスのプレフィックスとパスを指定しなければなりません。
$type を指定する場合は、それは
$type にどんな値が指定できるのかについては 要素のプラグインのセクション
を参照ください。$type を省略した場合は、
すべての型で用いる全般的なプレフィックスとみなします。
addDisplayGroupPrefixPath($prefix, $path):
addPrefixPath() と似ていますが、
クラスのプレフィックスとパスを指定しなければなりません。
しかし、表示グループではプラグインとして対応しているのはデコレータだけなので、
$type は不要です。
addElement() です。
このメソッドは、 addElement() は「流れるようなインターフェイス」
を実装しています。つまり、このメソッドは要素ではなく
createElement() を使いましょう。
概要は以下で説明します。しかし、
createElement() は要素をフォームにアタッチしないことに注意しましょう。
addElement() は実際には
createElement() をコールして作成した要素をフォームにアタッチしています。
getElement() メソッドを使用するか
オブジェクトのプロパティとして要素にアクセスします。
property:
createElement() メソッドを使用します。
getValues() を使用します。
getValue($name) を使用すると、
要素名を指定して特定の要素の値を取得することができます。
setDefaults() メソッドあるいは
populate() メソッドを使用します。
reset() メソッドを使用します。
setElementDecorators() に
setDecorators()
と同じようなデコレータの配列を渡すと、
各要素にそれまで設定されていたすべてのデコレータを上書きします。
この例では、単純に ViewHelper デコレータと
Label デコレータを設定します。
setElementDecorators() の 2 番目の引数に要素名の配列を指定します。
デフォルトでは、ここで指定した要素にのみデコレータが設定されます。
3 番目の引数を渡すこともできます。
これは、設定「したい」要素なのか設定「したくない」
要素なのかを表すフラグとなります。
false を渡すと、指定した
setElementDecorators()
はよい方法に見えますが、時には予期せぬ結果を引き起こすこともあります。
たとえば、ボタン系の要素 (Submit, Button, Reset)
では現在ラベルをボタンの値として使用しています。
そして ViewHelper デコレータや DtDdWrapper デコレータは、
余計なラベルやエラー、ヒントをレンダリングしないためにのみ用います。
上の例ではいくつかのラベルが重複してしまいます。
trim() するなどです。
createElement($element, $name = null, $options = null)
addElement($element, $name = null, $options = null)
addElements(array $elements)
setElements(array $elements)
getElement($name)
getElements()
removeElement($name)
clearElements()
setDefaults(array $defaults)
setDefault($name, $value)
getValue($name)
getValues()
getUnfilteredValue($name)
getUnfilteredValues()
setElementFilters(array $filters)
setElementDecorators(array $decorators)
addElementPrefixPath($prefix, $path, $type = null)
addElementPrefixPaths(array $spec)
addDisplayGroup() メソッドでインスタンスを作成することになります。
このメソッドの最初の引数には要素の配列を渡し、
表示グループの名前を 2 番目の引数で指定します。
オプションの 3 番目の引数で、設定の配列や
getDisplayGroup() メソッドを使用するか
あるいは表示グループ名を指定します。
addDisplayGroupPrefixPath() メソッドを使用します。
setDisplayGroupDecorators() に
setDecorators()
と同じようなデコレータの配列を渡すと、
各表示グループにそれまで設定されていたすべてのデコレータを上書きします。
この例では、単純に fieldset デコレータ
(FormElements デコレータは、要素を順次処理するために必須です)
を設定します。
addDisplayGroup()
には具象インスタンスを渡すことはできませんが、
どのクラスを使用するのかをオプションで指定することができます。
このときに使用するキーは 'displayGroupClass' です。
addDisplayGroup(array $elements, $name, $options = null)
addDisplayGroups(array $groups)
setDisplayGroups(array $groups)
getDisplayGroup($name)
getDisplayGroups()
removeDisplayGroup($name)
clearDisplayGroups()
setDisplayGroupDecorators(array $decorators)
addDisplayGroupPrefixPath($prefix, $path)
setDefaultDisplayGroupClass($class)
getDefaultDisplayGroupClass($class)
setOptions(array $options)setConfig(Zend_Config $config)setAttrib($key, $value)addAttribs(array $attribs)setAttribs(array $attribs)getAttrib($key)getAttribs()removeAttrib($key)clearAttribs()setName($name)getName()setDescription($value)getDescription()setLegend($legend)getLegend()setOrder($order)getOrder()createElement($type, $name, array $options = array())addElement($typeOrElement, $name, array $options = array())addElements(array $elements)setElements(array $elements)getElement($name)getElements()removeElement($name)clearElements()setPluginLoader(Zend_Loader_PluginLoader $loader)getPluginLoader()addPrefixPath($prefix, $path)addPrefixPaths(array $spec)addDecorator($decorator, $options = null)addDecorators(array $decorators)setDecorators(array $decorators)getDecorator($name)getDecorators()removeDecorator($name)clearDecorators()setView(Zend_View_Interface $view = null)getView()render(Zend_View_Interface $view = null)setTranslator(Zend_Translate_Adapter $translator = null)getTranslator()setDisableTranslator($flag)translatorIsDisabled()getSubForm($name) を使用するかあるいはサブフォームの名前を使用します。
setSubFormDecorators()
メソッドを使用します。次の例では、すべてのサブフォームに対して
単純に fieldset デコレータを設定します
(FormElements デコレータは、要素を順次処理するために必須です)。
addSubForm(Zend_Form $form, $name, $order = null)
addSubForms(array $subForms)
setSubForms(array $subForms)
getSubForm($name)
getSubForms()
removeSubForm($name)
clearSubForms()
setSubFormDecorators(array $decorators)
Countable
インターフェイスを実装しており、count 関数の引数として使用することができます。
<form> タグの属性となります。
addDecorator()
の最初の引数として渡すのではなく、ひとつの要素からなる配列を渡します。
この配列には、デコレータオブジェクトあるいはデコレータ名を指すエイリアスを指定します。
addDecorators() メソッドおよび
setDecorators() メソッドでは、
デコレータを表す配列を 'decorator' オプションに渡す必要があります。
addDecorator($decorator, $options = null)
addDecorators(array $decorators)
setDecorators(array $decorators)
getDecorator($name)
getDecorators()
removeDecorator($name)
clearDecorators()
__call()
で捕捉し、メソッド名の残りの部分にもとづいてデコレータを探します。
見つかった場合は、そのデコレータ
render() メソッドにコンテンツとして渡されます。次の例を参照ください。
This is fieldset content
"); ]]>isValid() メソッドを使用します。
isValid() はすべての必須要素の検証を行います。
また非必須要素の中で値が送信された要素についても検証します。
isValidPartial($data) を使用します。
isValidPartial() は、
data の項目にマッチする要素についてのみ検証を行います。
マッチする要素がなかった場合は処理をスキップします。
processAjax() が、まさにその作業を行うメソッドです。
getErrors() と
getMessages() で取得することができます。
getMessages() が返すメッセージは エラーコード/エラーメッセージ
の配列なので、getErrors() は通常は不要です。
isValid() メソッドに 2 番目の引数を渡します。
これは検証対象のデータの配列です。
これを使用すると、他の要素の入力内容をもとにした検証を
各要素で行うことができます。
例としては、「パスワード」欄と「パスワード(確認)」
があるユーザ登録フォームがあります。「パスワード」
要素の検証には「パスワード(確認)」の入力内容を使用することになるでしょう。
addErrorMessage($message):
フォームの検証エラーの際に表示するエラーメッセージを追加します。
複数回コールすると、新しいメッセージはスタックに追加されます。
addErrorMessages(array $messages):
フォームの検証エラーの際に表示する複数のエラーメッセージを追加します。
setErrorMessages(array $messages):
フォームの検証エラーの際に表示する複数のエラーメッセージを追加します。
それまでに設定されていたすべてのメッセージを上書きします。
getErrorMessages():
定義済みのカスタムエラーメッセージの一覧を取得します。
clearErrorMessages():
定義済みのカスタムエラーメッセージをすべて削除します。
markAsError():
検証に失敗したものとしてフォームにマークします。
addError($message):
エラーメッセージをカスタムエラーメッセージスタックに追加し、
フォームを無効とマークします。
addErrors(array $messages):
複数のエラーメッセージをカスタムエラーメッセージスタックに追加し、
フォームを無効とマークします。
setErrors(array $messages):
指定したメッセージでカスタムエラーメッセージスタックを上書きし、
フォームを無効とマークします。
setOptions(array $options)setConfig(Zend_Config $config)setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type = null)getPluginLoader($type = null)addPrefixPath($prefix, $path, $type = null) addPrefixPaths(array $spec)addElementPrefixPath($prefix, $path, $type = null)addElementPrefixPaths(array $spec)addDisplayGroupPrefixPath($prefix, $path)setAttrib($key, $value)addAttribs(array $attribs)setAttribs(array $attribs)getAttrib($key)getAttribs()removeAttrib($key)clearAttribs()setAction($action)getAction()setMethod($method)getMethod()setName($name)getName()addElement($element, $name = null, $options = null)addElements(array $elements)setElements(array $elements)getElement($name)getElements()removeElement($name)clearElements()setDefaults(array $defaults)setDefault($name, $value)getValue($name)getValues()getUnfilteredValue($name)getUnfilteredValues()setElementFilters(array $filters)setElementDecorators(array $decorators)addSubForm(Zend_Form $form, $name, $order = null)addSubForms(array $subForms)setSubForms(array $subForms)getSubForm($name)getSubForms()removeSubForm($name)clearSubForms()setSubFormDecorators(array $decorators)addDisplayGroup(array $elements, $name, $options = null)addDisplayGroups(array $groups)setDisplayGroups(array $groups)getDisplayGroup($name)getDisplayGroups()removeDisplayGroup($name)clearDisplayGroups()setDisplayGroupDecorators(array $decorators)populate(array $values)isValid(array $data)isValidPartial(array $data)processAjax(array $data)persistData()getErrors($name = null)getMessages($name = null)setView(Zend_View_Interface $view = null)getView()addDecorator($decorator, $options = null)addDecorators(array $decorators)setDecorators(array $decorators)getDecorator($name)getDecorators()removeDecorator($name)clearDecorators()render(Zend_View_Interface $view = null)setTranslator(Zend_Translate_Adapter $translator = null)getTranslator()setDisableTranslator($flag)translatorIsDisabled()setOptions() や setConfig() を用いて
(あるいはコンストラクタでオプションや
setAttrib() に渡されます。
prefixPaths は
addPrefixPaths() に渡されます。
elementPrefixPaths は
addElementPrefixPaths() に渡されます。
displayGroupPrefixPaths は
addDisplayGroupPrefixPaths() に渡されます。
setAttrib (ただし、setAttribs は動作します)setConfigsetDefaultsetOptionssetPluginLoadersetSubFormssetTranslatorsetViewinit()
メソッドでフォーム要素などの設定を行います。
loadDefaultDecorators() メソッドを上書きします。