クラス yii\helpers\Html
継承 | yii\helpers\Html » yii\helpers\BaseHtml |
---|---|
利用可能なバージョン | 2.0 |
ソースコード | https://github.com/yiisoft/yii2/blob/master/framework/helpers/Html.php |
Html は、一般的に使用される HTML タグを生成するための静的メソッドのセットを提供します。
このクラスのメソッドのほとんどすべてで、生成する HTML タグに追加の HTML 属性を設定できます。たとえば、$options
パラメータを使用して、HTML 要素に class
、style
、または id
を指定できます。詳細については、tag() メソッドのドキュメントを参照してください。
Html の詳細および使用方法については、HTML ヘルパーに関するガイド記事を参照してください。
パブリックプロパティ
プロパティ | 型 | 説明 | 定義元 |
---|---|---|---|
$attributeOrder | 配列 | タグ内の属性の優先順位。 | yii\helpers\BaseHtml |
$attributeRegex | 文字列 | 属性名の検証に使用される正規表現。 | yii\helpers\BaseHtml |
$dataAttributes | 配列 | 値が配列型の場合に特別に処理される必要のあるタグ属性のリスト。 | yii\helpers\BaseHtml |
$normalizeClassAttribute | ブール値 | タグ属性 class の重複するクラス名を削除するかどうか |
yii\helpers\BaseHtml |
$voidElements | 配列 | 空要素のリスト(要素名 => 1) | yii\helpers\BaseHtml |
パブリックメソッド
保護されたメソッド
メソッド | 説明 | 定義元 |
---|---|---|
activeBooleanInput() | ブール値入力を生成します。このメソッドは、主に activeCheckbox() および activeRadio() によって呼び出されます。 | yii\helpers\BaseHtml |
activeListInput() | 入力フィールドのリストを生成します。 | yii\helpers\BaseHtml |
booleanInput() | ブール値入力を生成します。 | yii\helpers\BaseHtml |
setActivePlaceholder() | モデル属性のラベルからプレースホルダーを生成します。 | yii\helpers\BaseHtml |
メソッド詳細
public static string a ( $text, $url = null, $options = [] ) | ||
$text | 文字列 |
リンクの本文。HTMLエンコードはされません。したがって、画像タグのようなHTMLコードを渡すことができます。エンドユーザーからの入力である場合は、XSS攻撃を防ぐためにencode()することを検討してください。 |
$url | 配列|文字列|null |
ハイパーリンクタグのURL。このパラメータはyii\helpers\Url::to()によって処理され、タグの "href" 属性に使用されます。このパラメータがnullの場合、"href" 属性は生成されません。 絶対URLを使用したい場合は、このメソッドにURLを渡す前に、次のようにyii\helpers\Url::to()を自分で呼び出すことができます。
|
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたハイパーリンク |
---|
public static function a($text, $url = null, $options = [])
{
if ($url !== null) {
$options['href'] = Url::to($url);
}
return static::tag('a', $text, $options);
}
定義元: yii\helpers\BaseHtml::activeBooleanInput()
ブール値入力を生成します。このメソッドは、主に activeCheckbox() および activeRadio() によって呼び出されます。
protected static string activeBooleanInput ( $type, $model, $attribute, $options = [] ) | ||
$type | 文字列 |
入力タイプ。これは、 |
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアによるタグのオプション。受け入れられる属性の詳細については、booleanInput()を参照してください。 |
return | 文字列 |
生成された入力要素 |
---|
protected static function activeBooleanInput($type, $model, $attribute, $options = [])
{
$name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
$value = static::getAttributeValue($model, $attribute);
if (!array_key_exists('value', $options)) {
$options['value'] = '1';
}
if (!array_key_exists('uncheck', $options)) {
$options['uncheck'] = '0';
} elseif ($options['uncheck'] === false) {
unset($options['uncheck']);
}
if (!array_key_exists('label', $options)) {
$options['label'] = static::encode($model->getAttributeLabel(static::getAttributeName($attribute)));
} elseif ($options['label'] === false) {
unset($options['label']);
}
$checked = "$value" === "{$options['value']}";
if (!array_key_exists('id', $options)) {
$options['id'] = static::getInputId($model, $attribute);
}
return static::$type($name, $checked, $options);
}
定義元: yii\helpers\BaseHtml::activeCheckbox()
指定されたモデル属性のラベルとともにチェックボックスのタグを生成します。
このメソッドは、モデル属性の値に従って "checked" タグ属性を生成します。
public static string activeCheckbox ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアによるタグのオプション。受け入れられる属性の詳細については、booleanInput()を参照してください。 |
return | 文字列 |
生成されたチェックボックスタグ |
---|
public static function activeCheckbox($model, $attribute, $options = [])
{
return static::activeBooleanInput('checkbox', $model, $attribute, $options);
}
定義元: yii\helpers\BaseHtml::activeCheckboxList()
チェックボックスのリストを生成します。
チェックボックスリストでは、listBox()のように複数の選択が可能です。その結果、対応する送信値は配列になります。チェックボックスリストの選択は、モデル属性の値から取得されます。
public static string activeCheckboxList ( $model, $attribute, $items, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$items | 配列 |
チェックボックスの生成に使用されるデータ項目。配列のキーはチェックボックスの値で、配列の値は対応するラベルです。 |
$options | 配列 |
チェックボックスリストのコンテナタグのオプション(name => config)。次のオプションは特別に処理されます。
属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたチェックボックスリスト |
---|
public static function activeCheckboxList($model, $attribute, $items, $options = [])
{
return static::activeListInput('checkboxList', $model, $attribute, $items, $options);
}
定義元: yii\helpers\BaseHtml::activeDropDownList()
指定されたモデル属性のドロップダウンリストを生成します。
ドロップダウンリストの選択は、モデル属性の値から取得されます。
public static string activeDropDownList ( $model, $attribute, $items, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$items | 配列 |
オプションのデータ項目。配列のキーはオプションの値で、配列の値は対応するオプションのラベルです。配列をネストすることもできます(つまり、一部の配列値も配列です)。サブ配列ごとに、ラベルがサブ配列に関連付けられたキーであるオプショングループが生成されます。データモデルのリストがある場合は、yii\helpers\ArrayHelper::map()を使用して、上記の形式に変換できます。 注:値とラベルは、このメソッドによって自動的にHTMLエンコードされ、ラベル内の空白もHTMLエンコードされます。 |
$options | 配列 |
名前と値のペアによるタグのオプション。次のオプションは特別に処理されます。
残りのオプションは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたドロップダウンリストタグ |
---|
public static function activeDropDownList($model, $attribute, $items, $options = [])
{
if (empty($options['multiple'])) {
return static::activeListInput('dropDownList', $model, $attribute, $items, $options);
}
return static::activeListBox($model, $attribute, $items, $options);
}
定義元: yii\helpers\BaseHtml::activeFileInput()
指定されたモデル属性のファイル入力タグを生成します。
このメソッドは、$options
で明示的に指定されていない限り、モデル属性の "name" および "value" タグ属性を自動的に生成します。さらに、$options
内にhiddenOptions
というキーを持つ別のHTMLオプション配列が定義されている場合、それは自身の$options
パラメーターとしてactiveHiddenInput
フィールドに渡されます。
public static string activeFileInput ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアで指定するタグのオプションです。これらは、結果として生成されるタグの属性としてレンダリングされます。値は、encode() を使用してHTMLエンコードされます。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。別のHTMLオプション配列である |
return | 文字列 |
生成された入力タグ |
---|
public static function activeFileInput($model, $attribute, $options = [])
{
$hiddenOptions = ['id' => null, 'value' => ''];
if (isset($options['name'])) {
$hiddenOptions['name'] = $options['name'];
}
// make sure disabled input is not sending any value
if (!empty($options['disabled'])) {
$hiddenOptions['disabled'] = $options['disabled'];
}
$hiddenOptions = ArrayHelper::merge($hiddenOptions, ArrayHelper::remove($options, 'hiddenOptions', []));
// Add a hidden field so that if a model only has a file field, we can
// still use isset($_POST[$modelClass]) to detect if the input is submitted.
// The hidden input will be assigned its own set of html options via `$hiddenOptions`.
// This provides the possibility to interact with the hidden field via client script.
// Note: For file-field-only model with `disabled` option set to `true` input submitting detection won't work.
return static::activeHiddenInput($model, $attribute, $hiddenOptions)
. static::activeInput('file', $model, $attribute, $options);
}
定義元: yii\helpers\BaseHtml::activeHiddenInput()
指定されたモデル属性の隠し入力タグを生成します。
このメソッドは、$options
で明示的に指定されていない限り、モデル属性の "name" および "value" タグ属性を自動的に生成します。
public static string activeHiddenInput ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアで指定するタグのオプションです。これらは、結果として生成されるタグの属性としてレンダリングされます。値は、encode() を使用してHTMLエンコードされます。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。 |
return | 文字列 |
生成された入力タグ |
---|
public static function activeHiddenInput($model, $attribute, $options = [])
{
return static::activeInput('hidden', $model, $attribute, $options);
}
定義元: yii\helpers\BaseHtml::activeHint()
指定されたモデル属性のヒントタグを生成します。
ヒントテキストは、yii\base\Model::getAttributeHint() を介して取得される、属性に関連付けられたヒントです。ヒントの内容を取得できない場合、メソッドは空の文字列を返します。
public static string activeHint ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアで指定するタグのオプションです。これらは、結果として生成されるタグの属性としてレンダリングされます。値は、encode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。以下のオプションは特別に処理されます。
属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたヒントタグ |
---|
public static function activeHint($model, $attribute, $options = [])
{
$attribute = static::getAttributeName($attribute);
$hint = isset($options['hint']) ? $options['hint'] : $model->getAttributeHint($attribute);
if (empty($hint)) {
return '';
}
$tag = ArrayHelper::remove($options, 'tag', 'div');
unset($options['hint']);
return static::tag($tag, $hint, $options);
}
定義元: yii\helpers\BaseHtml::activeInput()
指定されたモデル属性の入力タグを生成します。
このメソッドは、$options
で明示的に指定されていない限り、モデル属性の "name" および "value" タグ属性を自動的に生成します。
public static string activeInput ( $type, $model, $attribute, $options = [] ) | ||
$type | 文字列 |
入力タイプ (例: 'text', 'password') |
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアで指定するタグのオプションです。これらは、結果として生成されるタグの属性としてレンダリングされます。値は、encode() を使用してHTMLエンコードされます。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。 |
return | 文字列 |
生成された入力タグ |
---|
public static function activeInput($type, $model, $attribute, $options = [])
{
$name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
$value = isset($options['value']) ? $options['value'] : static::getAttributeValue($model, $attribute);
if (!array_key_exists('id', $options)) {
$options['id'] = static::getInputId($model, $attribute);
}
static::setActivePlaceholder($model, $attribute, $options);
self::normalizeMaxLength($model, $attribute, $options);
return static::input($type, $name, $value, $options);
}
定義元: yii\helpers\BaseHtml::activeLabel()
指定されたモデル属性のラベルタグを生成します。
ラベルテキストは、yii\base\Model::getAttributeLabel() を介して取得される、属性に関連付けられたラベルです。
public static string activeLabel ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアで指定するタグのオプションです。これらは、結果として生成されるタグの属性としてレンダリングされます。値は、encode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。以下のオプションは特別に処理されます。
属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたラベルタグ |
---|
public static function activeLabel($model, $attribute, $options = [])
{
$for = ArrayHelper::remove($options, 'for', static::getInputId($model, $attribute));
$attribute = static::getAttributeName($attribute);
$label = ArrayHelper::remove($options, 'label', static::encode($model->getAttributeLabel($attribute)));
return static::label($label, $for, $options);
}
public static string activeListBox ( $model, $attribute, $items, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$items | 配列 |
オプションのデータ項目。配列のキーはオプションの値で、配列の値は対応するオプションのラベルです。配列をネストすることもできます(つまり、一部の配列値も配列です)。サブ配列ごとに、ラベルがサブ配列に関連付けられたキーであるオプショングループが生成されます。データモデルのリストがある場合は、yii\helpers\ArrayHelper::map()を使用して、上記の形式に変換できます。 注:値とラベルは、このメソッドによって自動的にHTMLエンコードされ、ラベル内の空白もHTMLエンコードされます。 |
$options | 配列 |
名前と値のペアによるタグのオプション。次のオプションは特別に処理されます。
残りのオプションは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたリストボックスのタグ |
---|
public static function activeListBox($model, $attribute, $items, $options = [])
{
return static::activeListInput('listBox', $model, $attribute, $items, $options);
}
定義元: yii\helpers\BaseHtml::activeListInput()
入力フィールドのリストを生成します。
このメソッドは、主にactiveListBox()、activeRadioList()、およびactiveCheckboxList() によって呼び出されます。
protected static string activeListInput ( $type, $model, $attribute, $items, $options = [] ) | ||
$type | 文字列 |
入力タイプ。これは、'listBox'、'radioList'、または'checkBoxList'のいずれかになります。 |
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$items | 配列 |
入力フィールドの生成に使用されるデータ項目。配列キーは入力値であり、配列の値は対応するラベルです。 |
$options | 配列 |
入力リストのオプション(name => config)。サポートされる特別なオプションは、 |
return | 文字列 |
生成された入力リスト |
---|
protected static function activeListInput($type, $model, $attribute, $items, $options = [])
{
$name = ArrayHelper::remove($options, 'name', static::getInputName($model, $attribute));
$selection = ArrayHelper::remove($options, 'value', static::getAttributeValue($model, $attribute));
if (!array_key_exists('unselect', $options)) {
$options['unselect'] = '';
}
if (!array_key_exists('id', $options)) {
$options['id'] = static::getInputId($model, $attribute);
}
return static::$type($name, $selection, $items, $options);
}
定義元: yii\helpers\BaseHtml::activePasswordInput()
指定されたモデル属性のパスワード入力タグを生成します。
このメソッドは、$options
で明示的に指定されていない限り、モデル属性の "name" および "value" タグ属性を自動的に生成します。
public static string activePasswordInput ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアで指定するタグのオプションです。これらは、結果として生成されるタグの属性としてレンダリングされます。値は、encode() を使用してHTMLエンコードされます。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。次の特別なオプションが認識されます。
|
return | 文字列 |
生成された入力タグ |
---|
public static function activePasswordInput($model, $attribute, $options = [])
{
return static::activeInput('password', $model, $attribute, $options);
}
定義元: yii\helpers\BaseHtml::activeRadio()
指定されたモデル属性のラベルとともにラジオボタンタグを生成します。
このメソッドは、モデル属性の値に従って "checked" タグ属性を生成します。
public static string activeRadio ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアによるタグのオプション。受け入れられる属性の詳細については、booleanInput()を参照してください。 |
return | 文字列 |
生成されたラジオボタンのタグ |
---|
public static function activeRadio($model, $attribute, $options = [])
{
return static::activeBooleanInput('radio', $model, $attribute, $options);
}
定義場所: yii\helpers\BaseHtml::activeRadioList()
ラジオボタンのリストを生成します。
ラジオボタンリストは、チェックボックスリストに似ていますが、単一選択のみが許可されます。ラジオボタンの選択は、モデル属性の値から取得されます。
public static string activeRadioList ( $model, $attribute, $items, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$items | 配列 |
ラジオボタンの生成に使用されるデータ項目。配列のキーはラジオの値、配列の値は対応するラベルです。 |
$options | 配列 |
ラジオボタンリストのコンテナタグのオプション (name => config)。以下のオプションは特別に処理されます
属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたラジオボタンリスト |
---|
public static function activeRadioList($model, $attribute, $items, $options = [])
{
return static::activeListInput('radioList', $model, $attribute, $items, $options);
}
定義場所: yii\helpers\BaseHtml::activeTextInput()
指定されたモデル属性のテキスト入力タグを生成します。
このメソッドは、$options
で明示的に指定されていない限り、モデル属性の "name" および "value" タグ属性を自動的に生成します。
public static string activeTextInput ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアで指定するタグのオプションです。これらは、結果として生成されるタグの属性としてレンダリングされます。値は、encode() を使用してHTMLエンコードされます。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。次の特別なオプションが認識されます。
|
return | 文字列 |
生成された入力タグ |
---|
public static function activeTextInput($model, $attribute, $options = [])
{
return static::activeInput('text', $model, $attribute, $options);
}
定義場所: yii\helpers\BaseHtml::activeTextarea()
指定されたモデル属性のテキストエリアタグを生成します。
モデル属性の値が、テキストエリアの内容として使用されます。
public static string activeTextarea ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアで指定するタグのオプションです。これらは、結果として生成されるタグの属性としてレンダリングされます。値は、encode() を使用してHTMLエンコードされます。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。次の特別なオプションが認識されます。
|
return | 文字列 |
生成されたテキストエリアタグ |
---|
public static function activeTextarea($model, $attribute, $options = [])
{
$name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
if (isset($options['value'])) {
$value = $options['value'];
unset($options['value']);
} else {
$value = static::getAttributeValue($model, $attribute);
}
if (!array_key_exists('id', $options)) {
$options['id'] = static::getInputId($model, $attribute);
}
self::normalizeMaxLength($model, $attribute, $options);
static::setActivePlaceholder($model, $attribute, $options);
return static::textarea($name, $value, $options);
}
定義場所: yii\helpers\BaseHtml::addCssClass()
指定されたオプションに CSS クラス(または複数のクラス)を追加します。
CSSクラスがオプションに既に存在する場合、再度追加されることはありません。指定されたオプションでのクラス指定が配列であり、名前付き (文字列) キーを持つクラスが配置されている場合、そのようなキーの上書きは効果がありません。例えば
$options = ['class' => ['persistent' => 'initial']];
Html::addCssClass($options, ['persistent' => 'override']);
var_dump($options['class']); // outputs: array('persistent' => 'initial');
removeCssClass() も参照してください。
public static void addCssClass ( &$options, $class ) | ||
$options | 配列 |
変更されるオプション。 |
$class | string|array |
追加されるCSSクラス。 |
public static function addCssClass(&$options, $class)
{
if (isset($options['class'])) {
if (is_array($options['class'])) {
$options['class'] = self::mergeCssClasses($options['class'], (array) $class);
} else {
$classes = preg_split('/\s+/', $options['class'], -1, PREG_SPLIT_NO_EMPTY);
$options['class'] = implode(' ', self::mergeCssClasses($classes, (array) $class));
}
} else {
$options['class'] = $class;
}
}
定義場所: yii\helpers\BaseHtml::addCssStyle()
指定された CSS スタイルを HTML オプションに追加します。
オプションに style
要素が既に含まれている場合、新しいスタイルは既存のスタイルとマージされます。新しいスタイルと古いスタイルの両方にCSSプロパティが存在する場合、$overwrite
が true であれば、古いスタイルが上書きされる可能性があります。
例:
Html::addCssStyle($options, 'width: 100px; height: 200px');
こちらも参照してください
public static void addCssStyle ( &$options, $style, $overwrite = true ) | ||
$options | 配列 |
変更されるHTMLオプション。 |
$style | string|array |
新しいスタイル文字列 (例: |
$overwrite | ブール値 |
新しいスタイルにも既存のCSSプロパティが含まれている場合、上書きするかどうか。 |
public static function addCssStyle(&$options, $style, $overwrite = true)
{
if (!empty($options['style'])) {
$oldStyle = is_array($options['style']) ? $options['style'] : static::cssStyleToArray($options['style']);
$newStyle = is_array($style) ? $style : static::cssStyleToArray($style);
if (!$overwrite) {
foreach ($newStyle as $property => $value) {
if (isset($oldStyle[$property])) {
unset($newStyle[$property]);
}
}
}
$style = array_merge($oldStyle, $newStyle);
}
$options['style'] = is_array($style) ? static::cssStyleFromArray($style) : $style;
}
public static string beginForm ( $action = '', $method = 'post', $options = [] ) | ||
$action | array|string |
フォームアクションURL。このパラメーターは、yii\helpers\Url::to()によって処理されます。 |
$method | 文字列 |
フォームの送信メソッド。"post"、"get"、"put"、"delete" (大文字と小文字を区別しない) など。ほとんどのブラウザーは "post" と "get" のみをサポートするため、他のメソッドが指定された場合は、"post" を使用してシミュレートされ、実際のメソッドタイプを含む隠し入力が追加されます。詳細については、yii\web\Request::$methodParamを参照してください。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 特別なオプション
|
return | 文字列 |
生成されたフォーム開始タグ。 |
---|
public static function beginForm($action = '', $method = 'post', $options = [])
{
$action = Url::to($action);
$hiddenInputs = [];
$request = Yii::$app->getRequest();
if ($request instanceof Request) {
if (strcasecmp($method, 'get') && strcasecmp($method, 'post')) {
// simulate PUT, DELETE, etc. via POST
$hiddenInputs[] = static::hiddenInput($request->methodParam, $method);
$method = 'post';
}
$csrf = ArrayHelper::remove($options, 'csrf', true);
if ($csrf && $request->enableCsrfValidation && strcasecmp($method, 'post') === 0) {
$hiddenInputs[] = static::hiddenInput($request->csrfParam, $request->getCsrfToken());
}
}
if (!strcasecmp($method, 'get') && ($pos = strpos($action, '?')) !== false) {
// query parameters in the action are ignored for GET method
// we use hidden fields to add them back
foreach (explode('&', substr($action, $pos + 1)) as $pair) {
if (($pos1 = strpos($pair, '=')) !== false) {
$hiddenInputs[] = static::hiddenInput(
urldecode(substr($pair, 0, $pos1)),
urldecode(substr($pair, $pos1 + 1))
);
} else {
$hiddenInputs[] = static::hiddenInput(urldecode($pair), '');
}
}
$action = substr($action, 0, $pos);
}
$options['action'] = $action;
$options['method'] = $method;
$form = static::beginTag('form', $options);
if (!empty($hiddenInputs)) {
$form .= "\n" . implode("\n", $hiddenInputs);
}
return $form;
}
public static string beginTag ( $name, $options = [] ) | ||
$name | string|boolean|null |
タグ名。$name が |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成された開始タグ |
---|
public static function beginTag($name, $options = [])
{
if ($name === null || $name === false) {
return '';
}
return "<$name" . static::renderTagAttributes($options) . '>';
}
定義場所: yii\helpers\BaseHtml::booleanInput()
ブール値入力を生成します。
protected static string booleanInput ( $type, $name, $checked = false, $options = [] ) | ||
$type | 文字列 |
入力タイプ。これは、 |
$name | 文字列 |
name属性。 |
$checked | ブール値 |
チェックボックスをオンにするかどうか。 |
$options | 配列 |
名前と値のペアによるタグのオプション。次のオプションは特別に処理されます。
残りのオプションは、結果のチェックボックスタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたチェックボックスタグ |
---|
protected static function booleanInput($type, $name, $checked = false, $options = [])
{
// 'checked' option has priority over $checked argument
if (!isset($options['checked'])) {
$options['checked'] = (bool) $checked;
}
$value = array_key_exists('value', $options) ? $options['value'] : '1';
if (isset($options['uncheck'])) {
// add a hidden field so that if the checkbox is not selected, it still submits a value
$hiddenOptions = [];
if (isset($options['form'])) {
$hiddenOptions['form'] = $options['form'];
}
// make sure disabled input is not sending any value
if (!empty($options['disabled'])) {
$hiddenOptions['disabled'] = $options['disabled'];
}
$hidden = static::hiddenInput($name, $options['uncheck'], $hiddenOptions);
unset($options['uncheck']);
} else {
$hidden = '';
}
if (isset($options['label'])) {
$label = $options['label'];
$labelOptions = isset($options['labelOptions']) ? $options['labelOptions'] : [];
unset($options['label'], $options['labelOptions']);
$content = static::label(static::input($type, $name, $value, $options) . ' ' . $label, null, $labelOptions);
return $hidden . $content;
}
return $hidden . static::input($type, $name, $value, $options);
}
定義元: yii\helpers\BaseHtml::checkbox()
チェックボックス入力を生成します。
public static string checkbox ( $name, $checked = false, $options = [] ) | ||
$name | 文字列 |
name属性。 |
$checked | ブール値 |
チェックボックスをオンにするかどうか。 |
$options | 配列 |
名前と値のペアによるタグのオプション。受け入れられる属性の詳細については、booleanInput()を参照してください。 |
return | 文字列 |
生成されたチェックボックスタグ |
---|
public static function checkbox($name, $checked = false, $options = [])
{
return static::booleanInput('checkbox', $name, $checked, $options);
}
定義元: yii\helpers\BaseHtml::checkboxList()
チェックボックスのリストを生成します。
チェックボックスリストでは、listBox()のように、複数の選択が可能です。結果として、対応する送信値は配列になります。
public static string checkboxList ( $name, $selection = null, $items = [], $options = [] ) | ||
$name | 文字列 |
各チェックボックスのname属性です。 |
$selection | string|array|null |
選択された値です。単一選択の場合は文字列、複数選択の場合は配列です。 |
$items | 配列 |
チェックボックスの生成に使用されるデータ項目です。配列キーはチェックボックスの値であり、配列値は対応するラベルです。 |
$options | 配列 |
チェックボックスリストのコンテナタグのオプション(name => config)。次のオプションは特別に処理されます。
属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたチェックボックスリスト |
---|
public static function checkboxList($name, $selection = null, $items = [], $options = [])
{
if (substr($name, -2) !== '[]') {
$name .= '[]';
}
if (ArrayHelper::isTraversable($selection)) {
$selection = array_map('strval', ArrayHelper::toArray($selection));
}
$formatter = ArrayHelper::remove($options, 'item');
$itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
$encode = ArrayHelper::remove($options, 'encode', true);
$separator = ArrayHelper::remove($options, 'separator', "\n");
$tag = ArrayHelper::remove($options, 'tag', 'div');
$strict = ArrayHelper::remove($options, 'strict', false);
$lines = [];
$index = 0;
foreach ($items as $value => $label) {
$checked = $selection !== null &&
(!ArrayHelper::isTraversable($selection) && !strcmp($value, $selection)
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$value, $selection, $strict));
if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else {
$lines[] = static::checkbox($name, $checked, array_merge([
'value' => $value,
'label' => $encode ? static::encode($label) : $label,
], $itemOptions));
}
$index++;
}
if (isset($options['unselect'])) {
// add a hidden field so that if the list box has no option being selected, it still submits a value
$name2 = substr($name, -2) === '[]' ? substr($name, 0, -2) : $name;
$hiddenOptions = [];
// make sure disabled input is not sending any value
if (!empty($options['disabled'])) {
$hiddenOptions['disabled'] = $options['disabled'];
}
$hidden = static::hiddenInput($name2, $options['unselect'], $hiddenOptions);
unset($options['unselect'], $options['disabled']);
} else {
$hidden = '';
}
$visibleContent = implode($separator, $lines);
if ($tag === false) {
return $hidden . $visibleContent;
}
return $hidden . static::tag($tag, $visibleContent, $options);
}
定義元: yii\helpers\BaseHtml::csrfMetaTags()
CSRF トークン情報を含むメタタグを生成します。
yii\web\Request::$enableCsrfValidationも参照してください。
public static string csrfMetaTags ( ) | ||
return | 文字列 |
生成されたメタタグ |
---|
public static function csrfMetaTags()
{
$request = Yii::$app->getRequest();
if ($request instanceof Request && $request->enableCsrfValidation) {
return static::tag('meta', '', ['name' => 'csrf-param', 'content' => $request->csrfParam]) . "\n"
. static::tag('meta', '', ['name' => 'csrf-token', 'content' => $request->getCsrfToken()]) . "\n";
}
return '';
}
定義元: yii\helpers\BaseHtml::cssFile()
外部 CSS ファイルを参照する link タグを生成します。
yii\helpers\Url::to() も参照してください。
public static string cssFile ( $url, $options = [] ) | ||
$url | array|string |
外部CSSファイルのURLです。このパラメーターは、yii\helpers\Url::to()で処理されます。 |
$options | 配列 |
名前と値のペアによるタグのオプション。次のオプションは特別に処理されます。
残りのオプションは、結果のlinkタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたlinkタグ |
---|
public static function cssFile($url, $options = [])
{
if (!isset($options['rel'])) {
$options['rel'] = 'stylesheet';
}
$options['href'] = Url::to($url);
if (isset($options['condition'])) {
$condition = $options['condition'];
unset($options['condition']);
return self::wrapIntoCondition(static::tag('link', '', $options), $condition);
} elseif (isset($options['noscript']) && $options['noscript'] === true) {
unset($options['noscript']);
return '<noscript>' . static::tag('link', '', $options) . '</noscript>';
}
return static::tag('link', '', $options);
}
定義元: yii\helpers\BaseHtml::cssStyleFromArray()
CSS スタイル配列を文字列形式に変換します。
例:
print_r(Html::cssStyleFromArray(['width' => '100px', 'height' => '200px']));
// will display: 'width: 100px; height: 200px;'
public static string cssStyleFromArray ( array $style ) | ||
$style | 配列 |
CSSスタイルの配列です。配列キーはCSSプロパティ名であり、配列値は対応するCSSプロパティの値です。 |
return | 文字列 |
CSSスタイル文字列です。CSSスタイルが空の場合、nullが返されます。 |
---|
public static function cssStyleFromArray(array $style)
{
$result = '';
foreach ($style as $name => $value) {
$result .= "$name: $value; ";
}
// return null if empty to avoid rendering the "style" attribute
return $result === '' ? null : rtrim($result);
}
定義元: yii\helpers\BaseHtml::cssStyleToArray()
CSS スタイル文字列を配列形式に変換します。
配列キーはCSSプロパティ名であり、配列値は対応するCSSプロパティの値です。
例:
print_r(Html::cssStyleToArray('width: 100px; height: 200px;'));
// will display: ['width' => '100px', 'height' => '200px']
public static array cssStyleToArray ( $style ) | ||
$style | 文字列 |
CSSスタイルの文字列 |
return | 配列 |
CSSスタイルの配列表現 |
---|
public static function cssStyleToArray($style)
{
$result = [];
foreach (explode(';', $style) as $property) {
$property = explode(':', $property);
if (count($property) > 1) {
$result[trim($property[0])] = trim($property[1]);
}
}
return $result;
}
public static string decode ( $content ) | ||
$content | 文字列 |
デコードするコンテンツ |
return | 文字列 |
デコードされたコンテンツ |
---|
public static function decode($content)
{
return htmlspecialchars_decode($content, ENT_QUOTES);
}
定義元: yii\helpers\BaseHtml::dropDownList()
ドロップダウンリストを生成します。
public static string dropDownList ( $name, $selection = null, $items = [], $options = [] ) | ||
$name | 文字列 |
入力名 |
$selection | string|boolean|array|null |
選択された値。単一選択の場合は文字列/真偽値、複数選択の場合は配列。 |
$items | 配列 |
オプションのデータ項目。配列のキーはオプションの値で、配列の値は対応するオプションのラベルです。配列をネストすることもできます(つまり、一部の配列値も配列です)。サブ配列ごとに、ラベルがサブ配列に関連付けられたキーであるオプショングループが生成されます。データモデルのリストがある場合は、yii\helpers\ArrayHelper::map()を使用して、上記の形式に変換できます。 注:値とラベルは、このメソッドによって自動的にHTMLエンコードされ、ラベル内の空白もHTMLエンコードされます。 |
$options | 配列 |
名前と値のペアによるタグのオプション。次のオプションは特別に処理されます。
残りのオプションは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたドロップダウンリストタグ |
---|
public static function dropDownList($name, $selection = null, $items = [], $options = [])
{
if (!empty($options['multiple'])) {
return static::listBox($name, $selection, $items, $options);
}
$options['name'] = $name;
unset($options['unselect']);
$selectOptions = static::renderSelectOptions($selection, $items, $options);
return static::tag('select', "\n" . $selectOptions . "\n", $options);
}
定義元: yii\helpers\BaseHtml::encode()
特殊文字を HTML エンティティにエンコードします。
エンコードには アプリケーションの文字セット が使用されます。
こちらも参照してください
public static string encode ( $content, $doubleEncode = true ) | ||
$content | 文字列 |
エンコードするコンテンツ |
$doubleEncode | ブール値 |
|
return | 文字列 |
エンコードされたコンテンツ |
---|
public static function encode($content, $doubleEncode = true)
{
return htmlspecialchars((string)$content, ENT_QUOTES | ENT_SUBSTITUTE, Yii::$app ? Yii::$app->charset : 'UTF-8', $doubleEncode);
}
public static string endForm ( ) | ||
return | 文字列 |
生成されたタグ |
---|
public static function endForm()
{
return '</form>';
}
public static string endTag ( $name ) | ||
$name | string|boolean|null |
タグ名。$name が |
return | 文字列 |
生成された終了タグ |
---|
public static function endTag($name)
{
if ($name === null || $name === false) {
return '';
}
return "</$name>";
}
定義元: yii\helpers\BaseHtml::error()
指定されたモデル属性の最初の検証エラーを含むタグを生成します。
バリデーションエラーがない場合でも、このメソッドは空のエラータグを返します。
public static string error ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアで表されるタグオプション。値は encode() を使用して HTML エンコードされます。値が null の場合、対応する属性はレンダリングされません。 以下のオプションは特別に処理されます。
属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたラベルタグ |
---|
public static function error($model, $attribute, $options = [])
{
$attribute = static::getAttributeName($attribute);
$errorSource = ArrayHelper::remove($options, 'errorSource');
if ($errorSource !== null) {
$error = call_user_func($errorSource, $model, $attribute);
} else {
$error = $model->getFirstError($attribute);
}
$tag = ArrayHelper::remove($options, 'tag', 'div');
$encode = ArrayHelper::remove($options, 'encode', true);
return Html::tag($tag, $encode ? Html::encode($error) : $error, $options);
}
定義元: yii\helpers\BaseHtml::errorSummary()
検証エラーの概要を生成します。
バリデーションエラーがない場合、空のエラーサマリーマークアップが生成されますが、非表示になります。
public static string errorSummary ( $models, $options = [] ) | ||
$models | yii\base\Model|yii\base\Model[] |
バリデーションエラーを表示するモデル。 |
$options | 配列 |
名前と値のペアによるタグのオプション。次のオプションは特別に処理されます。
残りのオプションは、コンテナタグの属性としてレンダリングされます。 |
return | 文字列 |
生成されたエラーサマリー |
---|
public static function errorSummary($models, $options = [])
{
$header = isset($options['header']) ? $options['header'] : '<p>' . Yii::t('yii', 'Please fix the following errors:') . '</p>';
$footer = ArrayHelper::remove($options, 'footer', '');
$encode = ArrayHelper::remove($options, 'encode', true);
$showAllErrors = ArrayHelper::remove($options, 'showAllErrors', false);
$emptyClass = ArrayHelper::remove($options, 'emptyClass', null);
unset($options['header']);
$lines = self::collectErrors($models, $encode, $showAllErrors);
if (empty($lines)) {
// still render the placeholder for client-side validation use
$content = '<ul></ul>';
if ($emptyClass !== null) {
$options['class'] = $emptyClass;
} else {
$options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none';
}
} else {
$content = '<ul><li>' . implode("</li>\n<li>", $lines) . '</li></ul>';
}
return Html::tag('div', $header . $content . $footer, $options);
}
定義元: yii\helpers\BaseHtml::escapeJsRegularExpression()
JavaScript で使用するために正規表現をエスケープします。
public static string escapeJsRegularExpression ( $regexp ) | ||
$regexp | 文字列 |
エスケープする正規表現。 |
return | 文字列 |
エスケープされた結果。 |
---|
public static function escapeJsRegularExpression($regexp)
{
$pattern = preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $regexp);
$deliminator = substr($pattern, 0, 1);
$pos = strrpos($pattern, $deliminator, 1);
$flag = substr($pattern, $pos + 1);
if ($deliminator !== '/') {
$pattern = '/' . str_replace('/', '\\/', substr($pattern, 1, $pos - 1)) . '/';
} else {
$pattern = substr($pattern, 0, $pos + 1);
}
if (!empty($flag)) {
$pattern .= preg_replace('/[^igmu]/', '', $flag);
}
return $pattern;
}
定義元: yii\helpers\BaseHtml::fileInput()
ファイル入力フィールドを生成します。
ファイル入力フィールドを使用するには、囲むフォームの "enctype" 属性を "multipart/form-data" に設定する必要があります。フォームが送信されると、アップロードされたファイル情報は $_FILES[$name] を介して取得できます (PHPドキュメントを参照)。
public static string fileInput ( $name, $value = null, $options = [] ) | ||
$name | 文字列 |
name属性。 |
$value | string|null |
value属性です。nullの場合、value属性は生成されません。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたファイル入力タグ |
---|
public static function fileInput($name, $value = null, $options = [])
{
return static::input('file', $name, $value, $options);
}
定義元: yii\helpers\BaseHtml::getAttributeName()
指定された属性式から実際の属性名を返します。
属性式は、配列インデックスをプレフィックスまたはサフィックスとして持つ属性名です。主に表形式のデータ入力や配列型の入力で使用されます。以下にいくつかの例を示します。
[0]content
は、表形式のデータ入力で、表形式入力の最初のモデルの "content" 属性を表すために使用されます。dates[0]
は、"dates" 属性の最初の配列要素を表します。[0]dates[0]
は、表形式入力の最初のモデルの "dates" 属性の最初の配列要素を表します。
$attribute
にプレフィックスもサフィックスもない場合、変更せずに返されます。
public static string getAttributeName ( $attribute ) | ||
$attribute | 文字列 |
属性名または式 |
return | 文字列 |
接頭辞と接尾辞のない属性名。 |
---|---|---|
throws | yii\base\InvalidArgumentException |
属性名に非ワード文字が含まれている場合。 |
public static function getAttributeName($attribute)
{
if (preg_match(static::$attributeRegex, $attribute, $matches)) {
return $matches[2];
}
throw new InvalidArgumentException('Attribute name must contain word characters only.');
}
定義元: yii\helpers\BaseHtml::getAttributeValue()
指定された属性名または式の値を返します。
[0]dates[0]
のような属性式の場合、このメソッドは$model->dates[0]
の値を返します。属性式の詳細については、getAttributeName()を参照してください。
属性値がyii\db\ActiveRecordInterfaceのインスタンス、またはそのようなインスタンスの配列である場合、代わりにARインスタンスのプライマリ値が返されます。
public static string|array getAttributeValue ( $model, $attribute ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式 |
return | string|array |
対応する属性値 |
---|---|---|
throws | yii\base\InvalidArgumentException |
属性名に非ワード文字が含まれている場合。 |
public static function getAttributeValue($model, $attribute)
{
if (!preg_match(static::$attributeRegex, $attribute, $matches)) {
throw new InvalidArgumentException('Attribute name must contain word characters only.');
}
$attribute = $matches[2];
$value = $model->$attribute;
if ($matches[3] !== '') {
foreach (explode('][', trim($matches[3], '[]')) as $id) {
if ((is_array($value) || $value instanceof \ArrayAccess) && isset($value[$id])) {
$value = $value[$id];
} else {
return null;
}
}
}
// https://github.com/yiisoft/yii2/issues/1457
if (is_array($value)) {
foreach ($value as $i => $v) {
if ($v instanceof ActiveRecordInterface) {
$v = $v->getPrimaryKey(false);
$value[$i] = is_array($v) ? json_encode($v) : $v;
}
}
} elseif ($value instanceof ActiveRecordInterface) {
$value = $value->getPrimaryKey(false);
return is_array($value) ? json_encode($value) : $value;
}
return $value;
}
定義元: yii\helpers\BaseHtml::getInputId()
指定された属性名または式の適切な入力 ID を生成します。
public static string getInputId ( $model, $attribute ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の説明については、getAttributeName()を参照してください。 |
return | 文字列 |
生成された入力ID。 |
---|---|---|
throws | yii\base\InvalidArgumentException |
属性名に非ワード文字が含まれている場合。 |
public static function getInputId($model, $attribute)
{
$name = static::getInputName($model, $attribute);
return static::getInputIdByName($name);
}
定義元: yii\helpers\BaseHtml::getInputIdByName()
入力名を ID に変換します。
たとえば、$name
がPost[content]
の場合、このメソッドはpost-content
を返します。
public static string getInputIdByName ( $name ) | ||
$name | 文字列 |
入力名 |
return | 文字列 |
生成された入力ID |
---|
public static function getInputIdByName($name)
{
$charset = Yii::$app ? Yii::$app->charset : 'UTF-8';
$name = mb_strtolower($name, $charset);
return str_replace(['[]', '][', '[', ']', ' ', '.', '--'], ['', '-', '-', '', '-', '-', '-'], $name);
}
定義元: yii\helpers\BaseHtml::getInputName()
指定された属性名または式の適切な入力名を生成します。
このメソッドは、指定された属性のユーザー入力を収集するために、入力名として使用できる名前を生成します。名前は、モデルのフォーム名と指定された属性名に従って生成されます。たとえば、Post
モデルのフォーム名がPost
の場合、content
属性に対して生成される入力名はPost[content]
になります。
属性式の説明については、getAttributeName()を参照してください。
public static string getInputName ( $model, $attribute ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式 |
return | 文字列 |
生成された入力名 |
---|---|---|
throws | yii\base\InvalidArgumentException |
属性名に非ワード文字が含まれている場合。 |
public static function getInputName($model, $attribute)
{
$formName = $model->formName();
if (!preg_match(static::$attributeRegex, $attribute, $matches)) {
throw new InvalidArgumentException('Attribute name must contain word characters only.');
}
$prefix = $matches[1];
$attribute = $matches[2];
$suffix = $matches[3];
if ($formName === '' && $prefix === '') {
return $attribute . $suffix;
} elseif ($formName !== '') {
return $formName . $prefix . "[$attribute]" . $suffix;
}
throw new InvalidArgumentException(get_class($model) . '::formName() cannot be empty for tabular inputs.');
}
定義元: yii\helpers\BaseHtml::img()
画像タグを生成します。
public static string img ( $src, $options = [] ) | ||
$src | array|string |
画像URL。このパラメータは、yii\helpers\Url::to()によって処理されます。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 バージョン2.0.12以降では、 |
return | 文字列 |
生成された画像タグ。 |
---|
public static function img($src, $options = [])
{
$options['src'] = Url::to($src);
if (isset($options['srcset']) && is_array($options['srcset'])) {
$srcset = [];
foreach ($options['srcset'] as $descriptor => $url) {
$srcset[] = Url::to($url) . ' ' . $descriptor;
}
$options['srcset'] = implode(',', $srcset);
}
if (!isset($options['alt'])) {
$options['alt'] = '';
}
return static::tag('img', '', $options);
}
定義元: yii\helpers\BaseHtml::input()
指定されたタイプの入力タイプを生成します。
public static string input ( $type, $name = null, $value = null, $options = [] ) | ||
$type | 文字列 |
type属性。 |
$name | string|null |
name属性。nullの場合、name属性は生成されません。 |
$value | string|null |
value属性です。nullの場合、value属性は生成されません。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成された入力タグ |
---|
public static function input($type, $name = null, $value = null, $options = [])
{
if (!isset($options['type'])) {
$options['type'] = $type;
}
$options['name'] = $name;
$options['value'] = $value === null ? null : (string) $value;
return static::tag('input', '', $options);
}
定義元: yii\helpers\BaseHtml::jsFile()
外部 JavaScript ファイルを参照する script タグを生成します。
yii\helpers\Url::to() も参照してください。
public static string jsFile ( $url, $options = [] ) | ||
$url | 文字列 |
外部JavaScriptファイルのURL。このパラメータは、yii\helpers\Url::to()によって処理されます。 |
$options | 配列 |
名前と値のペアでのタグオプション。次のオプションは特別に処理されます。
残りのオプションは、結果のscriptタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性がどのようにレンダリングされるかの詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたscriptタグ |
---|
public static function jsFile($url, $options = [])
{
$options['src'] = Url::to($url);
if (isset($options['condition'])) {
$condition = $options['condition'];
unset($options['condition']);
return self::wrapIntoCondition(static::tag('script', '', $options), $condition);
}
return static::tag('script', '', $options);
}
定義元: yii\helpers\BaseHtml::label()
ラベルタグを生成します。
public static string label ( $content, $for = null, $options = [] ) | ||
$content | 文字列 |
ラベルテキスト。HTMLエンコードされません。したがって、画像タグなどのHTMLコードを渡すことができます。これがエンドユーザーからのものである場合は、XSS攻撃を防ぐためにencode()する必要があります。 |
$for | string|null |
このラベルが関連付けられているHTML要素のID。これがnullの場合、"for"属性は生成されません。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたラベルタグ |
---|
public static function label($content, $for = null, $options = [])
{
$options['for'] = $for;
return static::tag('label', $content, $options);
}
定義元: yii\helpers\BaseHtml::listBox()
リストボックスを生成します。
public static string listBox ( $name, $selection = null, $items = [], $options = [] ) | ||
$name | 文字列 |
入力名 |
$selection | string|boolean|array|null |
選択された値です。単一選択の場合は文字列、複数選択の場合は配列です。 |
$items | 配列 |
オプションのデータ項目。配列のキーはオプションの値で、配列の値は対応するオプションのラベルです。配列をネストすることもできます(つまり、一部の配列値も配列です)。サブ配列ごとに、ラベルがサブ配列に関連付けられたキーであるオプショングループが生成されます。データモデルのリストがある場合は、yii\helpers\ArrayHelper::map()を使用して、上記の形式に変換できます。 注:値とラベルは、このメソッドによって自動的にHTMLエンコードされ、ラベル内の空白もHTMLエンコードされます。 |
$options | 配列 |
名前と値のペアによるタグのオプション。次のオプションは特別に処理されます。
残りのオプションは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたリストボックスのタグ |
---|
public static function listBox($name, $selection = null, $items = [], $options = [])
{
if (!array_key_exists('size', $options)) {
$options['size'] = 4;
}
if (!empty($options['multiple']) && !empty($name) && substr_compare($name, '[]', -2, 2)) {
$name .= '[]';
}
$options['name'] = $name;
if (isset($options['unselect'])) {
// add a hidden field so that if the list box has no option being selected, it still submits a value
if (!empty($name) && substr_compare($name, '[]', -2, 2) === 0) {
$name = substr($name, 0, -2);
}
$hiddenOptions = [];
// make sure disabled input is not sending any value
if (!empty($options['disabled'])) {
$hiddenOptions['disabled'] = $options['disabled'];
}
$hidden = static::hiddenInput($name, $options['unselect'], $hiddenOptions);
unset($options['unselect']);
} else {
$hidden = '';
}
$selectOptions = static::renderSelectOptions($selection, $items, $options);
return $hidden . static::tag('select', "\n" . $selectOptions . "\n", $options);
}
定義元: yii\helpers\BaseHtml::mailto()
mailto ハイパーリンクを生成します。
public static string mailto ( $text, $email = null, $options = [] ) | ||
$text | 文字列 |
リンクの本文。HTMLエンコードはされません。したがって、画像タグのようなHTMLコードを渡すことができます。エンドユーザーからの入力である場合は、XSS攻撃を防ぐためにencode()することを検討してください。 |
string|null |
メールアドレス。これがnullの場合、最初のパラメータ(リンクの本文)がメールアドレスとして扱われ、使用されます。 |
|
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたmailtoリンク |
---|
public static function mailto($text, $email = null, $options = [])
{
$options['href'] = 'mailto:' . ($email === null ? $text : $email);
return static::tag('a', $text, $options);
}
定義元: yii\helpers\BaseHtml::ol()
順序付きリストを生成します。
public static string ol ( $items, $options = [] ) | ||
$items | array|Traversable |
リストを生成するためのアイテム。各アイテムは単一のリストアイテムを生成します。 |
$options | 配列 |
ラジオボタンリストのオプション(name => config)。次のオプションがサポートされています。
属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成された順序付きリスト。 |
---|
public static function ol($items, $options = [])
{
$options['tag'] = 'ol';
return static::ul($items, $options);
}
定義元: yii\helpers\BaseHtml::passwordInput()
パスワード入力フィールドを生成します。
public static string passwordInput ( $name, $value = null, $options = [] ) | ||
$name | 文字列 |
name属性。 |
$value | string|null |
value属性です。nullの場合、value属性は生成されません。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたパスワード入力タグ |
---|
public static function passwordInput($name, $value = null, $options = [])
{
return static::input('password', $name, $value, $options);
}
定義元: yii\helpers\BaseHtml::radio()
ラジオボタン入力を生成します。
public static string radio ( $name, $checked = false, $options = [] ) | ||
$name | 文字列 |
name属性。 |
$checked | ブール値 |
ラジオボタンをチェックする必要があるかどうか。 |
$options | 配列 |
名前と値のペアによるタグのオプション。受け入れられる属性の詳細については、booleanInput()を参照してください。 |
return | 文字列 |
生成されたラジオボタンのタグ |
---|
public static function radio($name, $checked = false, $options = [])
{
return static::booleanInput('radio', $name, $checked, $options);
}
定義元: yii\helpers\BaseHtml::radioList()
ラジオボタンのリストを生成します。
ラジオボタンリストは、チェックボックスリストと似ていますが、単一選択のみを許可します。
public static string radioList ( $name, $selection = null, $items = [], $options = [] ) | ||
$name | 文字列 |
各ラジオボタンのname属性。 |
$selection | string|array|null |
選択された値です。単一選択の場合は文字列、複数選択の場合は配列です。 |
$items | 配列 |
ラジオボタンを生成するために使用されるデータアイテム。配列キーはラジオボタンの値であり、配列の値は対応するラベルです。 |
$options | 配列 |
ラジオボタンリストのコンテナタグのオプション (name => config)。以下のオプションは特別に処理されます
属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたラジオボタンリスト |
---|
public static function radioList($name, $selection = null, $items = [], $options = [])
{
if (ArrayHelper::isTraversable($selection)) {
$selection = array_map('strval', ArrayHelper::toArray($selection));
}
$formatter = ArrayHelper::remove($options, 'item');
$itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
$encode = ArrayHelper::remove($options, 'encode', true);
$separator = ArrayHelper::remove($options, 'separator', "\n");
$tag = ArrayHelper::remove($options, 'tag', 'div');
$strict = ArrayHelper::remove($options, 'strict', false);
$hidden = '';
if (isset($options['unselect'])) {
// add a hidden field so that if the list box has no option being selected, it still submits a value
$hiddenOptions = [];
// make sure disabled input is not sending any value
if (!empty($options['disabled'])) {
$hiddenOptions['disabled'] = $options['disabled'];
}
$hidden = static::hiddenInput($name, $options['unselect'], $hiddenOptions);
unset($options['unselect'], $options['disabled']);
}
$lines = [];
$index = 0;
foreach ($items as $value => $label) {
$checked = $selection !== null &&
(!ArrayHelper::isTraversable($selection) && !strcmp($value, $selection)
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$value, $selection, $strict));
if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else {
$lines[] = static::radio($name, $checked, array_merge([
'value' => $value,
'label' => $encode ? static::encode($label) : $label,
], $itemOptions));
}
$index++;
}
$visibleContent = implode($separator, $lines);
if ($tag === false) {
return $hidden . $visibleContent;
}
return $hidden . static::tag($tag, $visibleContent, $options);
}
public static void removeCssClass ( &$options, $class ) | ||
$options | 配列 |
変更されるオプション。 |
$class | string|array |
削除するCSSクラス。 |
public static function removeCssClass(&$options, $class)
{
if (isset($options['class'])) {
if (is_array($options['class'])) {
$classes = array_diff($options['class'], (array) $class);
if (empty($classes)) {
unset($options['class']);
} else {
$options['class'] = $classes;
}
} else {
$classes = preg_split('/\s+/', $options['class'], -1, PREG_SPLIT_NO_EMPTY);
$classes = array_diff($classes, (array) $class);
if (empty($classes)) {
unset($options['class']);
} else {
$options['class'] = implode(' ', $classes);
}
}
}
}
定義元: yii\helpers\BaseHtml::removeCssStyle()
HTML オプションから指定された CSS スタイルを削除します。
例:
Html::removeCssStyle($options, ['width', 'height']);
addCssStyle()も参照してください。
public static void removeCssStyle ( &$options, $properties ) | ||
$options | 配列 |
変更されるHTMLオプション。 |
$properties | string|array |
削除するCSSプロパティ。単一のプロパティを削除する場合は、文字列を使用できます。 |
public static function removeCssStyle(&$options, $properties)
{
if (!empty($options['style'])) {
$style = is_array($options['style']) ? $options['style'] : static::cssStyleToArray($options['style']);
foreach ((array) $properties as $property) {
unset($style[$property]);
}
$options['style'] = static::cssStyleFromArray($style);
}
}
定義元: yii\helpers\BaseHtml::renderSelectOptions()
dropDownList() および listBox() で使用できる option タグをレンダリングします。
public static string renderSelectOptions ( $selection, $items, &$tagOptions = [] ) | ||
$selection | string|array|boolean|null |
選択された値。単一選択の場合は文字列/真偽値、複数選択の場合は配列。 |
$items | 配列 |
オプションのデータ項目。配列のキーはオプションの値で、配列の値は対応するオプションのラベルです。配列をネストすることもできます(つまり、一部の配列値も配列です)。サブ配列ごとに、ラベルがサブ配列に関連付けられたキーであるオプショングループが生成されます。データモデルのリストがある場合は、yii\helpers\ArrayHelper::map()を使用して、上記の形式に変換できます。 注:値とラベルは、このメソッドによって自動的にHTMLエンコードされ、ラベル内の空白もHTMLエンコードされます。 |
$tagOptions | 配列 |
dropDownList()またはlistBox()呼び出しに渡される$optionsパラメータ。このメソッドは、"prompt"、"options"、"groups"の要素があれば削除します。これらの要素の説明については、dropDownList()を参照してください。 |
return | 文字列 |
生成されたリストオプション |
---|
public static function renderSelectOptions($selection, $items, &$tagOptions = [])
{
if (ArrayHelper::isTraversable($selection)) {
$normalizedSelection = [];
foreach (ArrayHelper::toArray($selection) as $selectionItem) {
if (is_bool($selectionItem)) {
$normalizedSelection[] = $selectionItem ? '1' : '0';
} else {
$normalizedSelection[] = (string)$selectionItem;
}
}
$selection = $normalizedSelection;
} elseif (is_bool($selection)) {
$selection = $selection ? '1' : '0';
}
$lines = [];
$encodeSpaces = ArrayHelper::remove($tagOptions, 'encodeSpaces', false);
$encode = ArrayHelper::remove($tagOptions, 'encode', true);
$strict = ArrayHelper::remove($tagOptions, 'strict', false);
if (isset($tagOptions['prompt'])) {
$promptOptions = ['value' => ''];
if (is_string($tagOptions['prompt'])) {
$promptText = $tagOptions['prompt'];
} else {
$promptText = $tagOptions['prompt']['text'];
$promptOptions = array_merge($promptOptions, $tagOptions['prompt']['options']);
}
$promptText = $encode ? static::encode($promptText) : $promptText;
if ($encodeSpaces) {
$promptText = str_replace(' ', ' ', $promptText);
}
$lines[] = static::tag('option', $promptText, $promptOptions);
}
$options = isset($tagOptions['options']) ? $tagOptions['options'] : [];
$groups = isset($tagOptions['groups']) ? $tagOptions['groups'] : [];
unset($tagOptions['prompt'], $tagOptions['options'], $tagOptions['groups']);
$options['encodeSpaces'] = ArrayHelper::getValue($options, 'encodeSpaces', $encodeSpaces);
$options['encode'] = ArrayHelper::getValue($options, 'encode', $encode);
foreach ($items as $key => $value) {
if (is_array($value)) {
$groupAttrs = isset($groups[$key]) ? $groups[$key] : [];
if (!isset($groupAttrs['label'])) {
$groupAttrs['label'] = $key;
}
$attrs = ['options' => $options, 'groups' => $groups, 'encodeSpaces' => $encodeSpaces, 'encode' => $encode, 'strict' => $strict];
$content = static::renderSelectOptions($selection, $value, $attrs);
$lines[] = static::tag('optgroup', "\n" . $content . "\n", $groupAttrs);
} else {
$attrs = isset($options[$key]) ? $options[$key] : [];
$attrs['value'] = (string) $key;
if (!array_key_exists('selected', $attrs)) {
$selected = false;
if ($selection !== null) {
if (ArrayHelper::isTraversable($selection)) {
$selected = ArrayHelper::isIn((string)$key, $selection, $strict);
} elseif ($key === '' || $selection === '') {
$selected = $selection === $key;
} elseif ($strict) {
$selected = !strcmp((string)$key, (string)$selection);
} else {
$selected = $selection == $key;
}
}
$attrs['selected'] = $selected;
}
$text = $encode ? static::encode($value) : $value;
if ($encodeSpaces) {
$text = str_replace(' ', ' ', $text);
}
$lines[] = static::tag('option', $text, $attrs);
}
}
return implode("\n", $lines);
}
定義元: yii\helpers\BaseHtml::renderTagAttributes()
HTML タグ属性をレンダリングします。
値がboolean型の属性は、boolean属性として扱われます。
値がnullの属性はレンダリングされません。
属性の値は、encode()を使用してHTMLエンコードされます。
aria
およびdata
属性は、配列値に設定されると特別な処理が行われます。これらの場合、配列は「展開」され、ARIA/data属性のリストがレンダリングされます。たとえば、'aria' => ['role' => 'checkbox', 'value' => 'true']
は、aria-role="checkbox" aria-value="true"
としてレンダリングされます。
ネストされたdata
の値が配列に設定されている場合は、JSONエンコードされます。たとえば、'data' => ['params' => ['id' => 1, 'name' => 'yii']]
は、data-params='{"id":1,"name":"yii"}'
としてレンダリングされます。
addCssClass()も参照してください。
public static string renderTagAttributes ( $attributes ) | ||
$attributes | 配列 |
レンダリングされる属性。属性値は encode() を使用して HTML エンコードされます。 |
return | 文字列 |
レンダリング結果。属性が空でない場合、先頭に空白を含む文字列としてレンダリングされ(タグ内のタグ名に直接追加できるように)、属性がない場合は空の文字列が返されます。 |
---|
public static function renderTagAttributes($attributes)
{
if (count($attributes) > 1) {
$sorted = [];
foreach (static::$attributeOrder as $name) {
if (isset($attributes[$name])) {
$sorted[$name] = $attributes[$name];
}
}
$attributes = array_merge($sorted, $attributes);
}
$html = '';
foreach ($attributes as $name => $value) {
if (is_bool($value)) {
if ($value) {
$html .= " $name";
}
} elseif (is_array($value)) {
if (in_array($name, static::$dataAttributes)) {
foreach ($value as $n => $v) {
if (is_array($v)) {
$html .= " $name-$n='" . Json::htmlEncode($v) . "'";
} elseif (is_bool($v)) {
if ($v) {
$html .= " $name-$n";
}
} elseif ($v !== null) {
$html .= " $name-$n=\"" . static::encode($v) . '"';
}
}
} elseif ($name === 'class') {
if (empty($value)) {
continue;
}
if (static::$normalizeClassAttribute === true && count($value) > 1) {
// removes duplicate classes
$value = explode(' ', implode(' ', $value));
$value = array_unique($value);
}
$html .= " $name=\"" . static::encode(implode(' ', array_filter($value))) . '"';
} elseif ($name === 'style') {
if (empty($value)) {
continue;
}
$html .= " $name=\"" . static::encode(static::cssStyleFromArray($value)) . '"';
} else {
$html .= " $name='" . Json::htmlEncode($value) . "'";
}
} elseif ($value !== null) {
$html .= " $name=\"" . static::encode($value) . '"';
}
}
return $html;
}
定義元: yii\helpers\BaseHtml::resetButton()
リセットボタンタグを生成します。
public static string resetButton ( $content = 'リセット', $options = [] ) | ||
$content | 文字列 |
ボタンタグ内に囲まれたコンテンツです。HTMLエンコードはされません。したがって、画像タグなどのHTMLコードを渡すことができます。エンドユーザーから入力される場合は、XSS攻撃を防ぐためにencode()を検討する必要があります。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたリセットボタントグ |
---|
public static function resetButton($content = 'Reset', $options = [])
{
$options['type'] = 'reset';
return static::button($content, $options);
}
定義元: yii\helpers\BaseHtml::resetInput()
リセット入力ボタンを生成します。
public static string resetInput ( $label = 'リセット', $options = [] ) | ||
$label | string|null |
value属性です。nullの場合、value属性は生成されません。 |
$options | 配列 |
ボタンタグの属性。値は encode() を使用して HTML エンコードされます。値が null の属性は無視され、返されるタグには含まれません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。 |
return | 文字列 |
生成されたボタンタグ |
---|
public static function resetInput($label = 'Reset', $options = [])
{
$options['type'] = 'reset';
$options['value'] = $label;
return static::tag('input', '', $options);
}
定義元: yii\helpers\BaseHtml::script()
script タグを生成します。
public static string script ( $content, $options = [] ) | ||
$content | 文字列 |
スクリプトの内容 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたscriptタグ |
---|
public static function script($content, $options = [])
{
return static::tag('script', $content, $options);
}
定義元: yii\helpers\BaseHtml::setActivePlaceholder()
モデル属性のラベルからプレースホルダーを生成します。
protected static void setActivePlaceholder ( $model, $attribute, &$options = [] ) | ||
$model | yii\base\Model |
モデルオブジェクト |
$attribute | 文字列 |
属性名または式。属性式の形式については、getAttributeName()を参照してください。 |
$options | 配列 |
名前と値のペアの形式のタグオプション。これらは、結果のタグの属性としてレンダリングされます。値は encode() を使用して HTML エンコードされます。 |
protected static function setActivePlaceholder($model, $attribute, &$options = [])
{
if (isset($options['placeholder']) && $options['placeholder'] === true) {
$attribute = static::getAttributeName($attribute);
$options['placeholder'] = $model->getAttributeLabel($attribute);
}
}
定義元: yii\helpers\BaseHtml::style()
style タグを生成します。
public static string style ( $content, $options = [] ) | ||
$content | 文字列 |
スタイルコンテンツ |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成された style タグ |
---|
public static function style($content, $options = [])
{
return static::tag('style', $content, $options);
}
定義元: yii\helpers\BaseHtml::submitButton()
送信ボタンタグを生成します。
送信ボタンなどのフォーム要素に名前を付ける際は注意が必要です。jQuery のドキュメントによると、submit
、length
、method
など、競合を引き起こす可能性のある予約名がいくつかあります。
public static string submitButton ( $content = '送信', $options = [] ) | ||
$content | 文字列 |
ボタンタグ内に囲まれたコンテンツです。HTMLエンコードはされません。したがって、画像タグなどのHTMLコードを渡すことができます。エンドユーザーから入力される場合は、XSS攻撃を防ぐためにencode()を検討する必要があります。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成された送信ボタントグ |
---|
public static function submitButton($content = 'Submit', $options = [])
{
$options['type'] = 'submit';
return static::button($content, $options);
}
定義元: yii\helpers\BaseHtml::submitInput()
送信入力ボタンを生成します。
送信ボタンなどのフォーム要素に名前を付ける際は注意が必要です。jQuery のドキュメントによると、submit
、length
、method
など、競合を引き起こす可能性のある予約名がいくつかあります。
public static string submitInput ( $label = '送信', $options = [] ) | ||
$label | string|null |
value属性です。nullの場合、value属性は生成されません。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたボタンタグ |
---|
public static function submitInput($label = 'Submit', $options = [])
{
$options['type'] = 'submit';
$options['value'] = $label;
return static::tag('input', '', $options);
}
public static string tag ( $name, $content = '', $options = [] ) | ||
$name | string|boolean|null |
タグ名。$name が |
$content | 文字列 |
開始タグと終了タグで囲まれるコンテンツ。HTML エンコードはされません。エンドユーザーからのコンテンツである場合は、XSS 攻撃を防ぐために encode() を検討する必要があります。 |
$options | 配列 |
名前と値のペアの形式の HTML タグ属性 (HTML オプション)。これらは、結果のタグの属性としてレンダリングされます。値は encode() を使用して HTML エンコードされます。値が null の場合、対応する属性はレンダリングされません。 たとえば、 属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成された HTML タグ |
---|
public static function tag($name, $content = '', $options = [])
{
if ($name === null || $name === false) {
return $content;
}
$html = "<$name" . static::renderTagAttributes($options) . '>';
return isset(static::$voidElements[strtolower($name)]) ? $html : "$html$content</$name>";
}
定義元: yii\helpers\BaseHtml::textInput()
テキスト入力フィールドを生成します。
public static string textInput ( $name, $value = null, $options = [] ) | ||
$name | 文字列 |
name属性。 |
$value | string|null |
value属性です。nullの場合、value属性は生成されません。 |
$options | 配列 |
名前と値のペアによるタグのオプション。これらは、結果のタグの属性としてレンダリングされます。値は、encode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成されたテキスト入力タグ |
---|
public static function textInput($name, $value = null, $options = [])
{
return static::input('text', $name, $value, $options);
}
定義場所: yii\helpers\BaseHtml::textarea()
テキストエリア入力を生成します。
public static string textarea ( $name, $value = '', $options = [] ) | ||
$name | 文字列 |
入力名 |
$value | 文字列 |
入力値。 encode() を使用してエンコードされることに注意してください。 |
$options | 配列 |
名前と値のペアの形式でのタグオプション。これらは、結果のタグの属性としてレンダリングされます。値は encode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性がどのようにレンダリングされるかの詳細については、renderTagAttributes() を参照してください。以下の特別なオプションが認識されます。
|
return | 文字列 |
生成されたテキストエリアタグ |
---|
public static function textarea($name, $value = '', $options = [])
{
$options['name'] = $name;
$doubleEncode = ArrayHelper::remove($options, 'doubleEncode', true);
return static::tag('textarea', static::encode($value, $doubleEncode), $options);
}
定義場所: yii\helpers\BaseHtml::ul()
順序なしリストを生成します。
public static string ul ( $items, $options = [] ) | ||
$items | array|Traversable |
リストを生成するためのアイテム。各アイテムは単一のリストアイテムを生成します。 |
$options | 配列 |
ラジオボタンリストのオプション(name => config)。次のオプションがサポートされています。
属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。 |
return | 文字列 |
生成された順不同リスト。 |
---|
public static function ul($items, $options = [])
{
$tag = ArrayHelper::remove($options, 'tag', 'ul');
$encode = ArrayHelper::remove($options, 'encode', true);
$formatter = ArrayHelper::remove($options, 'item');
$separator = ArrayHelper::remove($options, 'separator', "\n");
$itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
if (empty($items)) {
return static::tag($tag, '', $options);
}
$results = [];
foreach ($items as $index => $item) {
if ($formatter !== null) {
$results[] = call_user_func($formatter, $item, $index);
} else {
$results[] = static::tag('li', $encode ? static::encode($item) : $item, $itemOptions);
}
}
return static::tag(
$tag,
$separator . implode($separator, $results) . $separator,
$options
);
}
コメントするには、サインアップまたはログインしてください。