BcFormHelper
extends FormHelper
in package
Uses
BcEventDispatcherTrait, BcContainerTrait
FormHelper 拡張クラス
Table of Contents
- $BcCkeditor : BcCkeditorHelper
- $BcHtml : BcHtmlHelper
- $BcUpload : BcUploadHelper
- $helpers : array<string|int, mixed>
- Other helpers used by FormHelper
- $_View : View
- View
- $formId : string
- フォームID
- ckeditor() : string
- CKEditorを出力する
- control() : string
- フォームコントロールを取得
- create() : string
- Returns an HTML form element.
- datePicker() : string
- カレンダーピッカー
- dateTimePicker() : string
- カレンダピッカーとタイムピッカー
- dispatchAfterForm() : string
- フォームの最後のフィールドの後に発動する前提としてイベントを発動する
- dispatchLayerEvent() : bool|Event
- イベントを発火
- editor() : string
- エディタを表示する
- end() : string
- Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden input fields where appropriate.
- file() : string
- ファイルインプットボックス出力
- generateList() : mixed
- モデルよりリストを生成する
- getControlSource() : array<string|int, mixed>|false
- コントロールソースを取得する Model側でメソッドを用意しておく必要がある
- getId() : string
- フォームのIDを取得する
- getService() : array<string|int, mixed>|mixed|object
- Get Service
- getTable() : Table|false
- フィールドに紐づくテーブルを取得する
- hasService() : bool
- Has Service
- hidden() : string
- Creates a hidden input field.
- input() : string
- Generates a form input element complete with label and wrapper div
- prefTag() : string
- 都道府県用のSELECTタグを表示する
- selectText() : string
- 文字列保存用複数選択コントロール
- setId() : string
- フォームのIDを設定する
- submit() : string
- Creates a submit button element. This method will generate `<input />` elements that can be used to submit, and reset forms by using $options. image submits can be created by supplying an image path for $caption.
- _generateOptions() : array<string|int, mixed>
- Generates option lists for common <select /> menus
- _selectOptions() : array<string|int, mixed>
- Returns an array of formatted OPTION/OPTGROUP elements
- createId() : string
- フォームのIDを作成する BcForm::create より呼出される事が前提
Properties
$BcCkeditor
public
BcCkeditorHelper
$BcCkeditor
$BcHtml
public
BcHtmlHelper
$BcHtml
$BcUpload
public
BcUploadHelper
$BcUpload
$helpers
Other helpers used by FormHelper
public
array<string|int, mixed>
$helpers
= ['Url', 'Js', 'Html', 'BaserCore.BcHtml', 'BaserCore.BcTime', 'BaserCore.BcText', 'BaserCore.BcUpload', 'BaserCore.BcCkeditor']
$_View
View
protected
View
$_View
$formId
フォームID
private
string
$formId
= null
Methods
ckeditor()
CKEditorを出力する
public
ckeditor(string $fieldName[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $fieldName : string
- $options : array<string|int, mixed> = []
Tags
Return values
string —control()
フォームコントロールを取得
public
control(string $fieldName[, array<string|int, mixed> $options = [] ]) : string
CakePHPの標準仕様をカスタマイズ
- labelタグを自動で付けない
- legendタグを自動で付けない
- errorタグを自動で付けない
Parameters
- $fieldName : string
- $options : array<string|int, mixed> = []
Tags
Return values
string —create()
Returns an HTML form element.
public
create([mixed $context = null ][, array<string|int, mixed> $options = [] ]) : string
Options:
-
type
Form method defaults to autodetecting based on the form context. If the form context's isCreate() method returns false, a PUT request will be done. -
method
Set the form's method attribute explicitly. -
url
The URL the form submits to. Can be a string or a URL array. -
encoding
Set the accept-charset encoding for the form. Defaults toConfigure::read('App.encoding')
-
enctype
Set the form encoding explicitly. By defaulttype => file
will setenctype
tomultipart/form-data
. -
templates
The templates you want to use for this form. Any templates will be merged on top of the already loaded templates. This option can either be a filename in /config that contains the templates you want to load, or an array of templates to use. -
context
Additional options for the context class. For example the EntityContext accepts a 'table' option that allows you to set the specific Table class the form should be based on. -
idPrefix
Prefix for generated ID attributes. -
valueSources
The sources that values should be read from. See FormHelper::setValueSources() -
templateVars
Provide template variables for the formStart template.
Parameters
- $context : mixed = null
-
The context for which the form is being defined. Can be a ContextInterface instance, ORM entity, ORM resultset, or an array of meta data. You can use
null
to make a context-less form. - $options : array<string|int, mixed> = []
-
An array of html attributes and options.
Tags
Return values
string —An formatted opening FORM tag.
datePicker()
カレンダーピッカー
public
datePicker(mixed $fieldName[, mixed $options = [] ]) : string
jquery-ui-1系 必須
Parameters
- $fieldName : mixed
- $options : mixed = []
Tags
Return values
string —html
dateTimePicker()
カレンダピッカーとタイムピッカー
public
dateTimePicker(string $fieldName[, array<string|int, mixed> $options = [] ]) : string
jquery.timepicker.js 必須
Parameters
- $fieldName : string
- $options : array<string|int, mixed> = []
Tags
Return values
string —dispatchAfterForm()
フォームの最後のフィールドの後に発動する前提としてイベントを発動する
public
dispatchAfterForm([string $type = '' ]) : string
発動側
フォームのの直前に記述して利用する
コールバック処理
プラグインのコールバック処理で CakeEvent::data['fields'] に 配列で行データを追加する事でフォームの最後に行を追加する事ができる。
イベント名
コントローラー名.Form.afterForm Or コントローラー名.Form.afterOptionForm
行データのキー(配列)
- title:見出欄
- input:入力欄
行データの追加例
$View = $event->subject(); // $event は、CakeEvent $input = $View->BcForm->input('Page.add_field', ['type' => 'input']); $event->setData('fields', [ [ 'title' => '追加フィールド', 'input' => $input ] ]);
Parameters
- $type : string = ''
-
フォームのタイプ タイプごとにイベントの登録ができる
Tags
Return values
string —行データ
dispatchLayerEvent()
イベントを発火
public
dispatchLayerEvent(string $name[, array<string|int, mixed> $data = [] ][, mixed $options = [] ]) : bool|Event
Parameters
- $name : string
- $data : array<string|int, mixed> = []
- $options : mixed = []
Tags
Return values
bool|Event —editor()
エディタを表示する
public
editor(string $fieldName[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $fieldName : string
- $options : array<string|int, mixed> = []
Return values
string —end()
Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden input fields where appropriate.
public
end([array<string|int, mixed> $secureAttributes = [] ]) : string
Resets some parts of the state, shared among multiple FormHelper::create() calls, to defaults.
Parameters
- $secureAttributes : array<string|int, mixed> = []
-
Secure attributes which will be passed as HTML attributes into the hidden input elements generated for the Security Component.
Tags
Return values
string —A closing FORM tag.
file()
ファイルインプットボックス出力
public
file(string $fieldName[, array<string|int, mixed> $options = [] ]) : string
画像の場合は画像タグ、その他の場合はファイルへのリンク そして削除用のチェックボックスを表示する
《オプション》 imgsize 画像のサイズを指定する rel A タグの rel 属性を指定 title A タグの title 属性を指定 link 大きいサイズへの画像へのリンク有無 delCheck 削除用チェックボックスの利用可否 force ファイルの存在有無に関わらず強制的に画像タグを表示するかどうか
Parameters
- $fieldName : string
- $options : array<string|int, mixed> = []
Tags
Return values
string —generateList()
モデルよりリストを生成する
public
generateList(string $modelName[, mixed $conditions = [] ][, mixed $fields = [] ][, mixed $order = [] ]) : mixed
Parameters
- $modelName : string
- $conditions : mixed = []
- $fields : mixed = []
- $order : mixed = []
Return values
mixed —リストまたは、false
getControlSource()
コントロールソースを取得する Model側でメソッドを用意しておく必要がある
public
getControlSource(string $field[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>|false
Parameters
- $field : string
-
フィールド名
- $options : array<string|int, mixed> = []
Tags
Return values
array<string|int, mixed>|false —コントロールソース
getId()
フォームのIDを取得する
public
getId() : string
BcFormHelper::create() の後に呼び出される事を前提とする
Tags
Return values
string —フォームID
getService()
Get Service
public
getService( $service) : array<string|int, mixed>|mixed|object
Parameters
Tags
Return values
array<string|int, mixed>|mixed|object —getTable()
フィールドに紐づくテーブルを取得する
public
getTable(string $fieldName) : Table|false
Parameters
- $fieldName : string
Tags
Return values
Table|false —hasService()
Has Service
public
hasService( $service) : bool
Parameters
Tags
Return values
bool —hidden()
Creates a hidden input field.
public
hidden(string $fieldName[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $fieldName : string
-
Name of a field, in the form of "Modelname.fieldname"
- $options : array<string|int, mixed> = []
-
Array of HTML attributes.
Tags
Return values
string —A generated hidden input
input()
Generates a form input element complete with label and wrapper div
public
input(string $fieldName[, array<string|int, mixed> $options = [] ]) : string
Options
See each field type method for more information. Any options that are part of
$attributes or $options for the different type methods can be included in $options
for input().i
Additionally, any unknown keys that are not in the list below, or part of the selected type's options
will be treated as a regular html attribute for the generated input.
-
type
- Force the type of widget you want. e.g.type => 'select'
-
label
- Either a string label, or an array of options for the label. See FormHelper::label(). -
div
- Eitherfalse
to disable the div, or an array of options for the div. See HtmlHelper::div() for more options. -
options
- For widgets that take options e.g. radio, select. -
error
- Control the error message that is produced. Set tofalse
to disable any kind of error reporting (field error and error messages). -
errorMessage
- Boolean to control rendering error messages (field error will still occur). -
empty
- String or boolean to enable empty select box options. -
before
- Content to place before the label + input. -
after
- Content to place after the label + input. -
between
- Content to place between the label + input. -
format
- Format template for element order. Any element that is not in the array, will not be in the output.- Default input format order: array('before', 'label', 'between', 'input', 'after', 'error')
- Default checkbox format order: array('before', 'input', 'between', 'label', 'after', 'error')
- Hidden input will not be formatted
- Radio buttons cannot have the order of input and label elements controlled with these settings.
Parameters
- $fieldName : string
-
This should be "Modelname.fieldname"
- $options : array<string|int, mixed> = []
-
Each type of input takes different options.
Tags
Return values
string —Completed form widget.
prefTag()
都道府県用のSELECTタグを表示する
public
prefTag(string $fieldName[, mixed $selected = null ][, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $convertKey = false ]) : string
Parameters
- $fieldName : string
-
Name attribute of the SELECT
- $selected : mixed = null
-
Selected option
- $attributes : array<string|int, mixed> = []
-
Array of HTML options for the opening SELECT element
- $convertKey : array<string|int, mixed> = false
-
true value = "value" / false value = "key"
Return values
string —都道府県用のSELECTタグ
selectText()
文字列保存用複数選択コントロール
public
selectText(string $fieldName[, array<string|int, mixed> $options = [] ][, mixed $selected = null ][, array<string|int, mixed> $attributes = [] ][, mixed $showEmpty = '' ]) : string
Parameters
- $fieldName : string
-
id,nameなどの名前
- $options : array<string|int, mixed> = []
-
optionタグの値
- $selected : mixed = null
-
selectedを付与する要素
- $attributes : array<string|int, mixed> = []
-
htmlの属性
- $showEmpty : mixed = ''
-
空要素の表示/非表示、初期値
Return values
string —setId()
フォームのIDを設定する
public
setId( $id) : string
BcFormHelper::create() の後に呼び出される事を前提とする
Parameters
Tags
Return values
string —新規フォームID
submit()
Creates a submit button element. This method will generate `<input />` elements that can be used to submit, and reset forms by using $options. image submits can be created by supplying an image path for $caption.
public
submit([string $caption = null ][, array<string|int, mixed> $options = [] ]) : string
Options
-
div
- Include a wrapping div? Defaults to true. Accepts sub options similar to FormHelper::input(). -
before
- Content to include before the input. -
after
- Content to include after the input. -
type
- Set to 'reset' for reset inputs. Defaults to 'submit' -
confirm
- JavaScript confirmation message. - Other attributes will be assigned to the input element.
Options
-
div
- Include a wrapping div? Defaults to true. Accepts sub options similar to FormHelper::input(). - Other attributes will be assigned to the input element.
Parameters
- $caption : string = null
-
The label appearing on the button OR if string contains :// or the extension .jpg, .jpe, .jpeg, .gif, .png use an image if the extension exists, AND the first character is /, image is relative to webroot, OR if the first character is not /, image is relative to webroot/img.
- $options : array<string|int, mixed> = []
-
Array of options. See above.
Tags
Return values
string —A HTML submit button
_generateOptions()
Generates option lists for common <select /> menus
protected
_generateOptions(string $name[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
- $name : string
-
List type name.
- $options : array<string|int, mixed> = []
-
Options list.
Return values
array<string|int, mixed> —_selectOptions()
Returns an array of formatted OPTION/OPTGROUP elements
protected
_selectOptions([array<string|int, mixed> $elements = [] ][, array<string|int, mixed> $parents = [] ][, bool $showParents = null ][, array<string|int, mixed> $attributes = [] ]) : array<string|int, mixed>
Parameters
- $elements : array<string|int, mixed> = []
-
Elements to format.
- $parents : array<string|int, mixed> = []
-
Parents for OPTGROUP.
- $showParents : bool = null
-
Whether to show parents.
- $attributes : array<string|int, mixed> = []
-
HTML attributes.
Return values
array<string|int, mixed> —createId()
フォームのIDを作成する BcForm::create より呼出される事が前提
protected
createId(EntityInterface $context[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $context : EntityInterface
- $options : array<string|int, mixed> = []