0 フォロワー

クラス yii\helpers\BaseHtml

継承yii\helpers\BaseHtml
サブクラスyii\helpers\Html
利用可能バージョン2.0
ソースコード https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php

BaseHtml は yii\helpers\Html の具体的な実装を提供します。

BaseHtml は使用しないでください。代わりに yii\helpers\Html を使用してください。

公開プロパティ

継承されたプロパティを非表示

プロパティ 説明 定義元
$attributeOrder 配列 タグ内の属性の優先順位。 yii\helpers\BaseHtml
$attributeRegex 文字列 属性名検証に使用される正規表現。 yii\helpers\BaseHtml
$dataAttributes 配列 値が配列型のときに特別に処理されるべきタグ属性のリスト。 yii\helpers\BaseHtml
$normalizeClassAttribute ブール値 タグ属性 `class` 内の重複するクラス名を削除するかどうか。 yii\helpers\BaseHtml
$voidElements 配列 空要素のリスト (要素名 => 1) yii\helpers\BaseHtml

公開メソッド

継承されたメソッドを非表示

メソッド 説明 定義元
a() ハイパーリンクタグを生成します。 yii\helpers\BaseHtml
activeCheckbox() 指定されたモデル属性のチェックボックスタグとラベルを生成します。 yii\helpers\BaseHtml
activeCheckboxList() チェックボックスのリストを生成します。 yii\helpers\BaseHtml
activeDropDownList() 指定されたモデル属性のドロップダウンリストを生成します。 yii\helpers\BaseHtml
activeFileInput() 指定されたモデル属性のファイル入力タグを生成します。 yii\helpers\BaseHtml
activeHiddenInput() 指定されたモデル属性の非表示入力タグを生成します。 yii\helpers\BaseHtml
activeHint() 指定されたモデル属性のヒントタグを生成します。 yii\helpers\BaseHtml
activeInput() 指定されたモデル属性の入力タグを生成します。 yii\helpers\BaseHtml
activeLabel() 指定されたモデル属性のラベルタグを生成します。 yii\helpers\BaseHtml
activeListBox() リストボックスを生成します。 yii\helpers\BaseHtml
activePasswordInput() 指定されたモデル属性のパスワード入力タグを生成します。 yii\helpers\BaseHtml
activeRadio() 指定されたモデル属性のラジオボタンタグとラベルを生成します。 yii\helpers\BaseHtml
activeRadioList() ラジオボタンのリストを生成します。 yii\helpers\BaseHtml
activeTextInput() 指定されたモデル属性のテキスト入力タグを生成します。 yii\helpers\BaseHtml
activeTextarea() 指定されたモデル属性のテキストエリアタグを生成します。 yii\helpers\BaseHtml
addCssClass() 指定されたオプションにCSSクラス(または複数のクラス)を追加します。 yii\helpers\BaseHtml
addCssStyle() 指定されたCSSスタイルをHTMLオプションに追加します。 yii\helpers\BaseHtml
beginForm() フォーム開始タグを生成します。 yii\helpers\BaseHtml
beginTag() 開始タグを生成します。 yii\helpers\BaseHtml
button() ボタンタグを生成します。 yii\helpers\BaseHtml
buttonInput() 入力ボタンを生成します。 yii\helpers\BaseHtml
checkbox() チェックボックス入力を生成します。 yii\helpers\BaseHtml
checkboxList() チェックボックスのリストを生成します。 yii\helpers\BaseHtml
csrfMetaTags() CSRFトークン情報を含むメタタグを生成します。 yii\helpers\BaseHtml
cssFile() 外部CSSファイルを参照するリンクタグを生成します。 yii\helpers\BaseHtml
cssStyleFromArray() CSSスタイル配列を文字列表現に変換します。 yii\helpers\BaseHtml
cssStyleToArray() CSSスタイル文字列を配列表現に変換します。 yii\helpers\BaseHtml
decode() 特殊なHTMLエンティティを対応する文字に戻してデコードします。 yii\helpers\BaseHtml
encode() 特殊文字をHTMLエンティティにエンコードします。 yii\helpers\BaseHtml
endForm() フォーム終了タグを生成します。 yii\helpers\BaseHtml
endTag() 終了タグを生成します。 yii\helpers\BaseHtml
error() 指定されたモデル属性の最初の検証エラーを含むタグを生成します。 yii\helpers\BaseHtml
errorSummary() 検証エラーのサマリーを生成します。 yii\helpers\BaseHtml
escapeJsRegularExpression() JavaScriptで使用する正規表現をエスケープします。 yii\helpers\BaseHtml
fileInput() ファイル入力フィールドを生成します。 yii\helpers\BaseHtml
getAttributeName() 指定された属性式から実際の属性名を返します。 yii\helpers\BaseHtml
getAttributeValue() 指定された属性名または式の値を返します。 yii\helpers\BaseHtml
getInputId() 指定された属性名または式に適した入力IDを生成します。 yii\helpers\BaseHtml
getInputIdByName() 入力名をIDに変換します。 yii\helpers\BaseHtml
getInputName() 指定された属性名または式に適した入力名を生成します。 yii\helpers\BaseHtml
hiddenInput() 非表示入力フィールドを生成します。 yii\helpers\BaseHtml
img() イメージタグを生成します。 yii\helpers\BaseHtml
input() 指定されたタイプの入力タイプを生成します。 yii\helpers\BaseHtml
jsFile() 外部JavaScriptファイルを参照するスクリプトタグを生成します。 yii\helpers\BaseHtml
label() ラベルタグを生成します。 yii\helpers\BaseHtml
listBox() リストボックスを生成します。 yii\helpers\BaseHtml
mailto() mailtoハイパーリンクを生成します。 yii\helpers\BaseHtml
ol() 順序付きリストを生成します。 yii\helpers\BaseHtml
passwordInput() パスワード入力フィールドを生成します。 yii\helpers\BaseHtml
radio() ラジオボタン入力を生成します。 yii\helpers\BaseHtml
radioList() ラジオボタンのリストを生成します。 yii\helpers\BaseHtml
removeCssClass() 指定されたオプションからCSSクラスを削除します。 yii\helpers\BaseHtml
removeCssStyle() 指定されたCSSスタイルをHTMLオプションから削除します。 yii\helpers\BaseHtml
renderSelectOptions() dropDownList()listBox() で使用できるオプションタグをレンダリングします。 yii\helpers\BaseHtml
renderTagAttributes() HTMLタグ属性をレンダリングします。 yii\helpers\BaseHtml
resetButton() リセットボタタグを生成します。 yii\helpers\BaseHtml
resetInput() リセット入力ボタンを生成します。 yii\helpers\BaseHtml
script() スクリプトタグを生成します。 yii\helpers\BaseHtml
style() スタイルタグを生成します。 yii\helpers\BaseHtml
submitButton() 送信ボタンタグを生成します。 yii\helpers\BaseHtml
submitInput() 送信入力ボタンを生成します。 yii\helpers\BaseHtml
tag() 完全なHTMLタグを生成します。 yii\helpers\BaseHtml
textInput() テキスト入力フィールドを生成します。 yii\helpers\BaseHtml
textarea() テキストエリア入力を生成します。 yii\helpers\BaseHtml
ul() 順序なしリストを生成します。 yii\helpers\BaseHtml

保護されたメソッド

継承されたメソッドを非表示

メソッド 説明 定義元
activeBooleanInput() ブール入力値を生成します。このメソッドは主に activeCheckbox()activeRadio() によって呼び出されます。 yii\helpers\BaseHtml
activeListInput() 入力フィールドのリストを生成します。 yii\helpers\BaseHtml
booleanInput() ブール入力を生成します。 yii\helpers\BaseHtml
setActivePlaceholder() モデル属性ラベルからプレースホルダーを生成します。 yii\helpers\BaseHtml

プロパティの詳細

継承されたプロパティを非表示

$attributeOrder public static property

タグ内の属性の優先順位。これは主に renderTagAttributes() によってレンダリングされる属性の順序に影響します。

public static array $attributeOrder = [
    
'type',
    
'id',
    
'class',
    
'name',
    
'value',
    
'href',
    
'src',
    
'srcset',
    
'form',
    
'action',
    
'method',
    
'selected',
    
'checked',
    
'readonly',
    
'disabled',
    
'multiple',
    
'size',
    
'maxlength',
    
'width',
    
'height',
    
'rows',
    
'cols',
    
'alt',
    
'title',
    
'rel',
    
'media',
]
$attributeRegex public static プロパティ (バージョン2.0.12から利用可能)

属性名検証に使用される正規表現。

public static string $attributeRegex '/(^|.*\])([\w\.\+]+)(\[.*|$)/u'
$dataAttributes public static プロパティ (バージョン2.0.3から利用可能)

配列型の値を持つタグ属性を特別な方法で処理する必要がある属性のリストです。 特に、data 属性の値が ['name' => 'xyz', 'age' => 13] の場合、1 つの属性ではなく、data-name="xyz" data-age="13" という 2 つの属性が生成されます。

public static array $dataAttributes = [
    
'aria',
    
'data',
    
'data-ng',
    
'ng',
]
$normalizeClassAttribute public static プロパティ (バージョン2.0.44から利用可能)

タグ属性 `class` 内の重複するクラス名を削除するかどうか。

参照

public static boolean $normalizeClassAttribute false
$voidElements public static プロパティ

空要素のリスト (要素名 => 1)

参照: https://html.spec.whatwg.org/multipage/syntax.html#void-element.

public static array $voidElements = [
    
'area' => 1,
    
'base' => 1,
    
'br' => 1,
    
'col' => 1,
    
'command' => 1,
    
'embed' => 1,
    
'hr' => 1,
    
'img' => 1,
    
'input' => 1,
    
'keygen' => 1,
    
'link' => 1,
    
'meta' => 1,
    
'param' => 1,
    
'source' => 1,
    
'track' => 1,
    
'wbr' => 1,
]

メソッドの詳細

継承されたメソッドを非表示

a() public static メソッド

ハイパーリンクタグを生成します。

参照: yii\helpers\Url::to().

public static string a ( $text, $url null, $options = [] )
$text 文字列

リンク本文。HTMLエンコードされません。そのため、画像タグなどのHTMLコードを渡すことができます。エンドユーザーからの入力を受け取る場合は、XSS攻撃を防ぐためにencode() を検討する必要があります。

$url array|string|null

ハイパーリンクタグのURL。このパラメータはyii\helpers\Url::to() によって処理され、タグの "href" 属性に使用されます。このパラメータがnullの場合、"href" 属性は生成されません。

絶対URLを使用したい場合は、このメソッドにURLを渡す前に、次のようにしてyii\helpers\Url::to() を自分で呼び出すことができます。

Html::a('link text', Url::to($url, true))
$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたハイパーリンク

                public static function a($text, $url = null, $options = [])
{
    if ($url !== null) {
        $options['href'] = Url::to($url);
    }
    return static::tag('a', $text, $options);
}

            
activeBooleanInput() protected static メソッド (バージョン2.0.9から利用可能)

ブール入力値を生成します。このメソッドは主に activeCheckbox()activeRadio() によって呼び出されます。

protected static string activeBooleanInput ( $type, $model, $attribute, $options = [] )
$type 文字列

入力タイプ。radio または checkbox のいずれかです。

$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアで表されるタグオプション。booleanInput() で、受け入れられる属性の詳細を確認してください。

戻り値 文字列

生成された入力要素

                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);
}

            
activeCheckbox() public static メソッド

指定されたモデル属性のチェックボックスタグとラベルを生成します。

このメソッドは、モデル属性の値に基づいて「checked」タグ属性を生成します。

public static string activeCheckbox ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアで表されるタグオプション。booleanInput() で、受け入れられる属性の詳細を確認してください。

戻り値 文字列

生成されるチェックボックスタグ

                public static function activeCheckbox($model, $attribute, $options = [])
{
    return static::activeBooleanInput('checkbox', $model, $attribute, $options);
}

            
activeCheckboxList() public static メソッド

チェックボックスのリストを生成します。

チェックボックスリストは、listBox()のように複数選択を許可します。その結果、送信される対応する値は配列になります。チェックボックスリストの選択は、モデル属性の値から取得されます。

public static string activeCheckboxList ( $model, $attribute, $items, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$items 配列

チェックボックスを生成するために使用されるデータ項目。配列のキーはチェックボックスの値、配列の値は対応するラベルです。

$options 配列

チェックボックスリストコンテナタグのオプション(name => config)。以下のオプションは特別に処理されます。

  • tag: string|false、コンテナ要素のタグ名。コンテナなしでチェックボックスをレンダリングする場合はfalse。 tag()も参照してください。
  • unselect: string、チェックボックスが選択されていない場合に送信される値。デフォルト値の送信を防ぐために、このオプションをnullに設定できます。このオプションが設定されていない場合、空文字列が送信されます。
  • encode: boolean、チェックボックスラベルをHTMLエンコードするかどうか。デフォルトはtrue。このオプションは、itemオプションが設定されている場合は無視されます。
  • separator: string、項目を区切るHTMLコード。
  • itemOptions: array、checkbox()を使用してチェックボックスタグを生成するためのオプション。
  • item: callable、$items内の単一項目に対応するHTMLコードの生成をカスタマイズするために使用できるコールバック。このコールバックのシグネチャは次のようになります。

    function ($index, $label, $name, $checked, $value)
    

    ここで、$indexはリスト全体におけるチェックボックスのゼロベースインデックス、$labelはチェックボックスのラベル、$name、$value、$checkedはチェックボックス入力の名前、値、チェック済みステータスを表します。

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成されるチェックボックスリスト

                public static function activeCheckboxList($model, $attribute, $items, $options = [])
{
    return static::activeListInput('checkboxList', $model, $attribute, $items, $options);
}

            
activeDropDownList() public static メソッド

指定されたモデル属性のドロップダウンリストを生成します。

ドロップダウンリストの選択は、モデル属性の値から取得されます。

public static string activeDropDownList ( $model, $attribute, $items, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$items 配列

オプションデータ項目。配列のキーはオプションの値、配列の値は対応するオプションのラベルです。配列はネストすることもできます(つまり、一部の配列の値も配列です)。各サブ配列に対して、ラベルがサブ配列に関連付けられたキーであるオプショングループが生成されます。データモデルのリストがある場合は、yii\helpers\ArrayHelper::map()を使用して、上記のように変換できます。

注記:値とラベルは、このメソッドによって自動的にHTMLエンコードされ、ラベル内の空白もHTMLエンコードされます。

$options 配列

名前と値のペアによるタグオプション。以下のオプションは特別に処理されます。

  • prompt: string、最初のオプションとして表示されるプロンプトテキスト。バージョン2.0.11以降、配列を使用して値をオーバーライドし、他のタグ属性を設定できます。

    ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']],
    
  • options: array、selectオプションタグの属性。配列のキーは有効なオプション値でなければならず、配列の値は対応するオプションタグの追加属性です。例えば、

    [
        'value1' => ['disabled' => true],
        'value2' => ['label' => 'value 2'],
    ];
    
  • groups: array、optgroupタグの属性。これは 'options' と同様の構造ですが、配列のキーは $items で指定された optgroup ラベルを表します。
  • encodeSpaces: bool、オプションのプロンプトとオプションの値の空白を ` ` 文字でエンコードするかどうか。デフォルトは false です。
  • encode: bool、オプションのプロンプトとオプションの値の文字をエンコードするかどうか。デフォルトは `true` です。このオプションは 2.0.3 以降で使用できます。

残りのオプションは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。

戻り値 文字列

生成されるドロップダウンリストタグ

                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);
}

            
activeFileInput() public static メソッド

指定されたモデル属性のファイル入力タグを生成します。

このメソッドは、`$options`で明示的に指定されていない限り、モデル属性に対して「name」と「value」タグ属性を自動的に生成します。さらに、`hiddenOptions`というキーを持つ別々のHTMLオプション配列が`$options`内に定義されている場合、それは自身の`$options`パラメータとして`activeHiddenInput`フィールドに渡されます。

public static string activeFileInput ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアによるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。別のHTMLオプション配列である`hiddenOptions`パラメータが定義されている場合、それは非表示入力に使用するために`$options`から抽出されます。

戻り値 文字列

生成される入力タグ

                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);
}

            
activeHiddenInput() public static メソッド

指定されたモデル属性の非表示入力タグを生成します。

このメソッドは、`$options`で明示的に指定されていない限り、モデル属性に対して「name」と「value」タグ属性を自動的に生成します。

public static string activeHiddenInput ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアによるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。

戻り値 文字列

生成される入力タグ

                public static function activeHiddenInput($model, $attribute, $options = [])
{
    return static::activeInput('hidden', $model, $attribute, $options);
}

            
activeHint() public static メソッド (バージョン2.0.4から利用可能)

指定されたモデル属性のヒントタグを生成します。

ヒントテキストは、yii\base\Model::getAttributeHint()を介して取得された、属性に関連付けられたヒントです。ヒントコンテンツを取得できない場合、メソッドは空文字列を返します。

public static string activeHint ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアによるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。以下のオプションは特別に処理されます。

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成されるヒントタグ

                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);
}

            
activeInput() public static メソッド

指定されたモデル属性の入力タグを生成します。

このメソッドは、`$options`で明示的に指定されていない限り、モデル属性に対して「name」と「value」タグ属性を自動的に生成します。

public static string activeInput ( $type, $model, $attribute, $options = [] )
$type 文字列

入力タイプ(例: 'text'、'password')

$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアによるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。

戻り値 文字列

生成される入力タグ

                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);
}

            
activeLabel() public static メソッド

指定されたモデル属性のラベルタグを生成します。

ラベルテキストは、属性に関連付けられたラベルであり、yii\base\Model::getAttributeLabel() を介して取得されます。

public static string activeLabel ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアによるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。以下のオプションは特別に処理されます。

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成されたラベルタグ

                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);
}

            
activeListBox() public static メソッド

リストボックスを生成します。

リストボックスの選択は、モデル属性の値から取得されます。

public static string activeListBox ( $model, $attribute, $items, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$items 配列

オプションデータ項目。配列のキーはオプションの値、配列の値は対応するオプションのラベルです。配列はネストすることもできます(つまり、一部の配列の値も配列です)。各サブ配列に対して、ラベルがサブ配列に関連付けられたキーであるオプショングループが生成されます。データモデルのリストがある場合は、yii\helpers\ArrayHelper::map()を使用して、上記のように変換できます。

注記:値とラベルは、このメソッドによって自動的にHTMLエンコードされ、ラベル内の空白もHTMLエンコードされます。

$options 配列

名前と値のペアによるタグオプション。以下のオプションは特別に処理されます。

  • prompt: string、最初のオプションとして表示されるプロンプトテキスト。バージョン2.0.11以降、配列を使用して値をオーバーライドし、他のタグ属性を設定できます。

    ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']],
    
  • options: array、selectオプションタグの属性。配列のキーは有効なオプション値でなければならず、配列の値は対応するオプションタグの追加属性です。例えば、

    [
        'value1' => ['disabled' => true],
        'value2' => ['label' => 'value 2'],
    ];
    
  • groups: array、optgroupタグの属性。これは 'options' と同様の構造ですが、配列のキーは $items で指定された optgroup ラベルを表します。
  • unselect: string、オプションが選択されていない場合に送信される値。この属性が設定されている場合、隠しフィールドが生成され、複数モードでオプションが選択されていない場合でも、投稿されたunselect値を取得できます。
  • encodeSpaces: bool、オプションのプロンプトとオプションの値の空白を ` ` 文字でエンコードするかどうか。デフォルトは false です。
  • encode: bool、オプションのプロンプトとオプションの値の文字をエンコードするかどうか。デフォルトは `true` です。このオプションは 2.0.3 以降で使用できます。

残りのオプションは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。

戻り値 文字列

生成されたリストボックスタグ

                public static function activeListBox($model, $attribute, $items, $options = [])
{
    return static::activeListInput('listBox', $model, $attribute, $items, $options);
}

            
activeListInput() protected static メソッド

入力フィールドのリストを生成します。

このメソッドは主に、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)。サポートされている特別なオプションは、$typeで指定された入力タイプによって異なります。

戻り値 文字列

生成された入力リスト

                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);
}

            
activePasswordInput() public static メソッド

指定されたモデル属性のパスワード入力タグを生成します。

このメソッドは、`$options`で明示的に指定されていない限り、モデル属性に対して「name」と「value」タグ属性を自動的に生成します。

public static string activePasswordInput ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアによるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。次の特別なオプションが認識されます。

  • maxlength: integer|boolean、maxlengthがtrueに設定され、モデル属性が文字列バリデーターによって検証される場合、maxlengthオプションはyii\validators\StringValidator::$maxと[[\yii\validators\StringValidator::length]の最大値を取ります。これはバージョン2.0.6以降で使用可能になり、バージョン2.0.42以降はlengthを考慮して改善されました。
  • placeholder: string|boolean、placeholdertrueの場合、$modelの属性ラベルがプレースホルダーとして使用されます(この動作はバージョン2.0.14以降で使用可能です)。
戻り値 文字列

生成される入力タグ

                public static function activePasswordInput($model, $attribute, $options = [])
{
    return static::activeInput('password', $model, $attribute, $options);
}

            
activeRadio() public static メソッド

指定されたモデル属性のラジオボタンタグとラベルを生成します。

このメソッドは、モデル属性の値に基づいて「checked」タグ属性を生成します。

public static string activeRadio ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアで表されるタグオプション。booleanInput() で、受け入れられる属性の詳細を確認してください。

戻り値 文字列

生成されたラジオボタンタグ

                public static function activeRadio($model, $attribute, $options = [])
{
    return static::activeBooleanInput('radio', $model, $attribute, $options);
}

            
activeRadioList() public static メソッド

ラジオボタンのリストを生成します。

ラジオボタンリストはチェックボックスリストに似ていますが、単一選択のみが可能です。ラジオボタンの選択は、モデル属性の値から取得されます。

public static string activeRadioList ( $model, $attribute, $items, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$items 配列

ラジオボタンを生成するために使用されるデータ項目。配列のキーはラジオ値であり、配列の値は対応するラベルです。

$options 配列

ラジオボタンリストコンテナタグのオプション(name => config)。次のオプションは特別に処理されます。

  • tag: string|false、コンテナ要素のタグ名。コンテナなしでラジオボタンをレンダリングするにはfalse。 tag()も参照してください。
  • unselect: string、ラジオボタンが選択されていない場合に送信される値。デフォルト値の送信を防ぐために、このオプションをnullに設定できます。このオプションが設定されていない場合、空文字列が送信されます。
  • encode: boolean、チェックボックスラベルをHTMLエンコードするかどうか。デフォルトはtrue。このオプションは、itemオプションが設定されている場合は無視されます。
  • separator: string、項目を区切るHTMLコード。
  • itemOptions: array、radio()を使用してラジオボタンタグを生成するためのオプション。
  • item: callable、$items内の単一項目に対応するHTMLコードの生成をカスタマイズするために使用できるコールバック。このコールバックのシグネチャは次のようになります。

    function ($index, $label, $name, $checked, $value)
    

    ここで、$indexはリスト全体におけるラジオボタンのゼロベースのインデックス、$labelはラジオボタンのラベル、$name、$value、$checkedはラジオボタン入力の名前、値、およびチェック状態を表します。

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成されたラジオボタンリスト

                public static function activeRadioList($model, $attribute, $items, $options = [])
{
    return static::activeListInput('radioList', $model, $attribute, $items, $options);
}

            
activeTextInput() public static メソッド

指定されたモデル属性のテキスト入力タグを生成します。

このメソッドは、`$options`で明示的に指定されていない限り、モデル属性に対して「name」と「value」タグ属性を自動的に生成します。

public static string activeTextInput ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアによるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。次の特別なオプションが認識されます。

  • maxlength: integer|boolean、maxlengthがtrueに設定され、モデル属性が文字列バリデーターによって検証される場合、maxlengthオプションはyii\validators\StringValidator::$maxと[[\yii\validators\StringValidator::length]の最大値を取ります。これはバージョン2.0.3以降で使用可能になり、バージョン2.0.42以降はlengthを考慮して改善されました。
  • placeholder: string|boolean、placeholdertrueの場合、$modelの属性ラベルがプレースホルダーとして使用されます(この動作はバージョン2.0.14以降で使用可能です)。
戻り値 文字列

生成される入力タグ

                public static function activeTextInput($model, $attribute, $options = [])
{
    return static::activeInput('text', $model, $attribute, $options);
}

            
activeTextarea() public static メソッド

指定されたモデル属性のテキストエリアタグを生成します。

モデル属性値は、テキストエリアの内容として使用されます。

public static string activeTextarea ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

名前と値のペアによるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。次の特別なオプションが認識されます。

  • maxlength: integer|boolean、maxlengthがtrueに設定され、モデル属性が文字列バリデーターによって検証される場合、maxlengthオプションはyii\validators\StringValidator::$maxと[[\yii\validators\StringValidator::length]の最大値を取ります。これはバージョン2.0.6以降で使用可能になり、バージョン2.0.42以降はlengthを考慮して改善されました。
  • placeholder: string|boolean、placeholdertrueの場合、$modelの属性ラベルがプレースホルダーとして使用されます(この動作はバージョン2.0.14以降で使用可能です)。
戻り値 文字列

生成されたテキストエリアタグ

                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);
}

            
addCssClass() public static メソッド

指定されたオプションに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 文字列|配列

追加する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;
    }
}

            
addCssStyle() public static メソッド

指定されたCSSスタイルをHTMLオプションに追加します。

オプションに既にstyle要素が含まれている場合、新しいスタイルは既存のスタイルとマージされます。新しいスタイルと古いスタイルの両方にCSSプロパティが存在する場合、$overwriteがtrueの場合、古いスタイルが上書きされる可能性があります。

例:

Html::addCssStyle($options, 'width: 100px; height: 200px');

参照

public static void addCssStyle ( &$options, $style, $overwrite true )
$options 配列

変更するHTMLオプション。

$style 文字列|配列

新しいスタイル文字列(例:'width: 100px; height: 200px')または配列(例:['width' => '100px', 'height' => '200px'])。

$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;
}

            
beginForm() public static メソッド

フォーム開始タグを生成します。

こちらも参照してください endForm().

public static 文字列 beginForm ( $action '', $method 'post', $options = [] )
$action 配列|文字列

フォームのアクションURL。このパラメータは yii\helpers\Url::to() によって処理されます。

$method 文字列

フォームの送信方法(例:"post"、"get"、"put"、"delete"。大文字小文字は区別されません)。ほとんどのブラウザは"post"と"get"しかサポートしていないため、他のメソッドが指定された場合は"post"を使用してシミュレートされ、実際のメソッドタイプを含む非表示の入力フィールドが追加されます。yii\web\Request::$methodParam を参照してください。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

特別なオプション

  • csrf: CSRFの非表示入力フィールドを生成するかどうか。デフォルトはtrueです。
戻り値 文字列

生成されたフォームの開始タグ。

                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;
}

            
beginTag() public static メソッド

開始タグを生成します。

参照

public static 文字列 beginTag ( $name, $options = [] )
$name 文字列|ブール値|null

タグ名。$nameがnullまたはfalseの場合、対応するコンテンツはタグなしでレンダリングされます。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成された開始タグ

                public static function beginTag($name, $options = [])
{
    if ($name === null || $name === false) {
        return '';
    }
    return "<$name" . static::renderTagAttributes($options) . '>';
}

            
booleanInput() protected static メソッド (バージョン 2.0.9 以降で使用可能)

ブール入力を生成します。

protected static 文字列 booleanInput ( $type, $name, $checked false, $options = [] )
$type 文字列

入力タイプ。radio または checkbox のいずれかです。

$name 文字列

name属性。

$checked ブール値

チェックボックスをチェックするかどうか。

$options 配列

名前と値のペアによるタグオプション。以下のオプションは特別に処理されます。

  • uncheck: 文字列、チェックボックスのチェックされていない状態に関連付けられた値。この属性が存在する場合、チェックボックスがチェックされておらず送信された場合でも、この属性の値が非表示の入力フィールドを介してサーバーに送信されるように、非表示の入力フィールドが生成されます。
  • label: 文字列、チェックボックスの横に表示されるラベル。HTMLエンコードされません。そのため、画像タグなどのHTMLコードを渡すことができます。これがエンドユーザーからのものである場合、XSS攻撃を防ぐために encode() する必要があります。このオプションが指定されている場合、チェックボックスはラベルタグで囲まれます。
  • labelOptions: 配列、ラベルタグのHTML属性。"label"オプションを設定しない限り、このオプションを設定しないでください。

残りのオプションは、結果のチェックボックスタグの属性としてレンダリングされます。値は encode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されるチェックボックスタグ

                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);
}

            
button() public static メソッド

ボタンタグを生成します。

public static 文字列 button ( $content 'Button', $options = [] )
$content 文字列

ボタンタグ内に囲まれたコンテンツ。HTMLエンコードされません。そのため、画像タグなどのHTMLコードを渡すことができます。これがエンドユーザーからのものである場合、XSS攻撃を防ぐために encode() することを検討する必要があります。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたボタンタグ

                public static function button($content = 'Button', $options = [])
{
    if (!isset($options['type'])) {
        $options['type'] = 'button';
    }
    return static::tag('button', $content, $options);
}

            
buttonInput() public static メソッド

入力ボタンを生成します。

public static 文字列 buttonInput ( $label 'Button', $options = [] )
$label 文字列|null

value属性。nullの場合、value属性は生成されません。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたボタンタグ

                public static function buttonInput($label = 'Button', $options = [])
{
    $options['type'] = 'button';
    $options['value'] = $label;
    return static::tag('input', '', $options);
}

            
checkbox() public static メソッド

チェックボックス入力を生成します。

public static 文字列 checkbox ( $name, $checked false, $options = [] )
$name 文字列

name属性。

$checked ブール値

チェックボックスをチェックするかどうか。

$options 配列

名前と値のペアで表されるタグオプション。booleanInput() で、受け入れられる属性の詳細を確認してください。

戻り値 文字列

生成されるチェックボックスタグ

                public static function checkbox($name, $checked = false, $options = [])
{
    return static::booleanInput('checkbox', $name, $checked, $options);
}

            
checkboxList() public static メソッド

チェックボックスのリストを生成します。

チェックボックスリストは、listBox()と同様に複数選択を許可します。そのため、対応する送信値は配列になります。

public static string checkboxList ( $name, $selection null, $items = [], $options = [] )
$name 文字列

各チェックボックスのname属性。

$selection string|array|null

選択された値。単一選択の場合は文字列、複数選択の場合は配列。

$items 配列

チェックボックスを生成するために使用されるデータ項目。配列のキーはチェックボックスの値、配列の値は対応するラベルです。

$options 配列

チェックボックスリストコンテナタグのオプション(name => config)。以下のオプションは特別に処理されます。

  • tag: string|false、コンテナ要素のタグ名。コンテナなしでチェックボックスをレンダリングする場合はfalse。 tag()も参照してください。
  • unselect: string、チェックボックスが1つも選択されていない場合に送信される値。このオプションを設定すると、隠し入力フィールドが生成されます。
  • disabled: boolean、unselectオプションによって生成された隠し入力フィールドを無効にするかどうか。デフォルトはfalse。このオプションはバージョン2.0.16から利用可能です。
  • encode: boolean、チェックボックスラベルをHTMLエンコードするかどうか。デフォルトはtrue。このオプションは、itemオプションが設定されている場合は無視されます。
  • strict: boolean、$selectionが配列で、この値がtrueの場合、$itemsのキーに対して厳密な比較が行われます。デフォルトはfalse。このオプションは2.0.37から利用可能です。
  • separator: string、項目を区切るHTMLコード。
  • itemOptions: array、checkbox()を使用してチェックボックスタグを生成するためのオプション。
  • item: callable、$items内の単一項目に対応するHTMLコードの生成をカスタマイズするために使用できるコールバック。このコールバックのシグネチャは次のようになります。

    function ($index, $label, $name, $checked, $value)
    

    ここで、$indexはリスト全体におけるチェックボックスの0ベースのインデックス、$labelはチェックボックスのラベル、$name、$value、$checkedはそれぞれチェックボックス入力のname、value、チェック済み状態を表します。

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成されるチェックボックスリスト

                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);
}

            
csrfMetaTags() public static メソッド

CSRFトークン情報を含むメタタグを生成します。

こちらも参照してください yii\web\Request::$enableCsrfValidation.

public static string csrfMetaTags ( )
戻り値 文字列

生成されたメタタグ

                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 '';
}

            
cssFile() public static メソッド

外部CSSファイルを参照するリンクタグを生成します。

参照: yii\helpers\Url::to().

public static string cssFile ( $url, $options = [] )
$url 配列|文字列

外部CSSファイルのURL。このパラメータはyii\helpers\Url::to()によって処理されます。

$options 配列

名前と値のペアによるタグオプション。以下のオプションは特別に処理されます。

  • condition: IEの条件付きコメントを指定します(例:lt IE 9)。これを指定すると、生成されたlinkタグは条件付きコメント内に囲まれます。これは主に古いバージョンのIEブラウザをサポートするために役立ちます。
  • noscript: trueに設定すると、linkタグは<noscript>タグでラップされます。

残りのオプションは、結果のlinkタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。renderTagAttributes()で属性のレンダリング方法の詳細を参照してください。

戻り値 文字列

生成された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);
}

            
cssStyleFromArray() public static メソッド

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プロパティ値です。

戻り値 文字列

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);
}

            
cssStyleToArray() public static メソッド

CSSスタイル文字列を配列表現に変換します。

配列のキーはCSSプロパティ名、配列の値は対応するCSSプロパティ値です。

例:

print_r(Html::cssStyleToArray('width: 100px; height: 200px;'));
// will display: ['width' => '100px', 'height' => '200px']
public static array cssStyleToArray ( $style )
$style 文字列

CSSスタイル文字列

戻り値 配列

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;
}

            
decode() public static メソッド

特殊なHTMLエンティティを対応する文字に戻してデコードします。

これはencode()の逆です。

参照

public static string decode ( $content )
$content 文字列

デコードされるコンテンツ

戻り値 文字列

デコードされたコンテンツ

                public static function decode($content)
{
    return htmlspecialchars_decode($content, ENT_QUOTES);
}

            
encode() public static メソッド

特殊文字をHTMLエンティティにエンコードします。

アプリケーションの文字セットがエンコードに使用されます。

参照

public static string encode ( $content, $doubleEncode true )
$content 文字列

エンコードされるコンテンツ

$doubleEncode ブール値

$content内のHTMLエンティティをエンコードするかどうか。falseの場合、$content内のHTMLエンティティはさらにエンコードされません。

戻り値 文字列

エンコードされたコンテンツ

                public static function encode($content, $doubleEncode = true)
{
    return htmlspecialchars((string)$content, ENT_QUOTES | ENT_SUBSTITUTE, Yii::$app ? Yii::$app->charset : 'UTF-8', $doubleEncode);
}

            
endForm() public static メソッド

フォーム終了タグを生成します。

こちらも参照してください beginForm().

public static string endForm ( )
戻り値 文字列

生成されたタグ

                public static function endForm()
{
    return '</form>';
}

            
endTag() public static メソッド

終了タグを生成します。

参照

public static string endTag ( $name )
$name 文字列|ブール値|null

タグ名。$nameがnullまたはfalseの場合、対応するコンテンツはタグなしでレンダリングされます。

戻り値 文字列

生成された終了タグ

                public static function endTag($name)
{
    if ($name === null || $name === false) {
        return '';
    }
    return "</$name>";
}

            
error() public static メソッド

指定されたモデル属性の最初の検証エラーを含むタグを生成します。

検証エラーがなくても、このメソッドは空のエラータグを返します。

public static string error ( $model, $attribute, $options = [] )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または式。getAttributeName() を参照して、属性式の形式を確認してください。

$options 配列

タグオプション(名前と値のペア)。値はencode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。

以下のオプションは特別に処理されます。

  • tag: この属性はタグ名を指定します。設定しない場合は、「div」が使用されます。tag()も参照してください。
  • encode: ブール値。falseに設定すると、エラーメッセージはエンコードされません。
  • errorSource (2.0.14以降): \Closure|callable, エラーメッセージを取得するために呼び出されるコールバック関数。コールバック関数のシグネチャはfunction ($model, $attribute)でなければならず、文字列を返します。設定されていない場合、$model->getFirstError()メソッドが呼び出されます。

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成されたラベルタグ

                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);
}

            
errorSummary() public static メソッド

検証エラーのサマリーを生成します。

検証エラーがない場合でも、空のエラーサマリーマークアップが生成されますが、非表示になります。

public static string errorSummary ( $models, $options = [] )
$models yii\base\Model|yii\base\Model[]

検証エラーを表示するモデル。

$options 配列

名前と値のペアによるタグオプション。以下のオプションは特別に処理されます。

  • header: string, エラーサマリーのヘッダーHTML。設定しない場合は、デフォルトのプロンプト文字列が使用されます。
  • footer: string, エラーサマリーのフッターHTML。デフォルトは空文字列です。
  • encode: ブール値。falseに設定すると、エラーメッセージはエンコードされません。デフォルトはtrueです。
  • showAllErrors: ブール値。trueに設定すると、各属性のすべてのエラーメッセージが表示されます。それ以外の場合は、各属性の最初のエラーメッセージのみが表示されます。デフォルトはfalseです。このオプションは2.0.10以降で使用可能です。
  • emptyClass: string, 空のサマリーに追加されるクラス名。

その他のオプションは、コンテナタグの属性としてレンダリングされます。

戻り値 文字列

生成されたエラーサマリー

                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);
}

            
escapeJsRegularExpression() public static メソッド (バージョン2.0.6以降で使用可能)

JavaScriptで使用する正規表現をエスケープします。

public static string escapeJsRegularExpression ( $regexp )
$regexp 文字列

エスケープする正規表現。

戻り値 文字列

エスケープされた結果。

                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;
}

            
fileInput() public static メソッド

ファイル入力フィールドを生成します。

ファイル入力フィールドを使用するには、囲んでいるフォームの「enctype」属性を「multipart/form-data」に設定する必要があります。フォームが送信された後、アップロードされたファイル情報は$_FILES[$name]から取得できます(PHPのマニュアルを参照)。

public static string fileInput ( $name, $value null, $options = [] )
$name 文字列

name属性。

$value 文字列|null

value属性。nullの場合、value属性は生成されません。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたファイル入力タグ

                public static function fileInput($name, $value = null, $options = [])
{
    return static::input('file', $name, $value, $options);
}

            
getAttributeName() public static メソッド

指定された属性式から実際の属性名を返します。

属性式とは、配列インデックスで接頭辞および/または接尾辞を付けた属性名です。主に表形式データ入力や配列型入力で使用されます。以下にいくつかの例を示します。

  • [0]contentは、表形式データ入力において、表形式入力の最初のモデルの「content」属性を表すために使用されます。
  • dates[0]は、「dates」属性の最初の配列要素を表します。
  • [0]dates[0]は、表形式入力の最初のモデルの「dates」属性の最初の配列要素を表します。

$attributeに接頭辞も接尾辞もない場合、変更せずに返されます。

public static string getAttributeName ( $attribute )
$attribute 文字列

属性名または属性式

戻り値 文字列

接頭辞と接尾辞のない属性名。

例外発生 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.');
}

            
getAttributeValue() public static メソッド

指定された属性名または式の値を返します。

[0]dates[0]のような属性式の場合、このメソッドは$model->dates[0]の値を返します。属性式に関する詳細はgetAttributeName()を参照してください。

属性値がyii\db\ActiveRecordInterfaceのインスタンスまたはそのようなインスタンスの配列である場合、代わりにARインスタンスの主キー値が返されます。

public static string|array getAttributeValue ( $model, $attribute )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または属性式

戻り値 文字列|配列

対応する属性値

例外発生 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;
}

            
getInputId() public static メソッド

指定された属性名または式に適した入力IDを生成します。

public static string getInputId ( $model, $attribute )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または属性式。getAttributeName()で属性式の説明を参照してください。

戻り値 文字列

生成された入力ID。

例外発生 yii\base\InvalidArgumentException

属性名に英数字以外の文字が含まれている場合。

                public static function getInputId($model, $attribute)
{
    $name = static::getInputName($model, $attribute);
    return static::getInputIdByName($name);
}

            
getInputIdByName() public static メソッド (バージョン2.0.43以降で使用可能)

入力名をIDに変換します。

例えば、$namePost[content]の場合、このメソッドはpost-contentを返します。

public static string getInputIdByName ( $name )
$name 文字列

入力名

戻り値 文字列

生成された入力ID

                public static function getInputIdByName($name)
{
    $charset = Yii::$app ? Yii::$app->charset : 'UTF-8';
    $name = mb_strtolower($name, $charset);
    return str_replace(['[]', '][', '[', ']', ' ', '.', '--'], ['', '-', '-', '', '-', '-', '-'], $name);
}

            
getInputName() public static メソッド

指定された属性名または式に適した入力名を生成します。

このメソッドは、指定された属性のユーザー入力を収集するための入力名として使用できる名前を生成します。名前は、モデルのフォーム名と指定された属性名に従って生成されます。例えば、Postモデルのフォーム名がPostの場合、content属性に対して生成される入力名はPost[content]になります。

getAttributeName()で属性式の説明を参照してください。

public static string getInputName ( $model, $attribute )
$model yii\base\Model

モデルオブジェクト

$attribute 文字列

属性名または属性式

戻り値 文字列

生成された入力名

例外発生 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.');
}

            
hiddenInput() public static メソッド

非表示入力フィールドを生成します。

public static string hiddenInput ( $name, $value null, $options = [] )
$name 文字列

name属性。

$value 文字列|null

value属性。nullの場合、value属性は生成されません。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成された非表示入力タグ

                public static function hiddenInput($name, $value = null, $options = [])
{
    return static::input('hidden', $name, $value, $options);
}

            
img() public static メソッド

イメージタグを生成します。

public static string img ( $src, $options = [] )
$src 配列|文字列

画像URL。このパラメータはyii\helpers\Url::to()によって処理されます。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

バージョン2.0.12以降、srcsetオプションをキーが記述子で値がURLである配列として渡すことができます。すべてのURLはyii\helpers\Url::to()によって処理されます。

戻り値 文字列

生成された画像タグ。

                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);
}

            
input() public static メソッド

指定されたタイプの入力タイプを生成します。

public static string input ( $type, $name null, $value null, $options = [] )
$type 文字列

type属性。

$name 文字列|null

name属性。nullの場合、name属性は生成されません。

$value 文字列|null

value属性。nullの場合、value属性は生成されません。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成される入力タグ

                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);
}

            
jsFile() public static メソッド

外部JavaScriptファイルを参照するスクリプトタグを生成します。

参照: yii\helpers\Url::to().

public static string jsFile ( $url, $options = [] )
$url 文字列

外部JavaScriptファイルのURL。このパラメータはyii\helpers\Url::to()によって処理されます。

$options 配列

名前と値のペアで指定されたタグオプション。以下のオプションは特別に処理されます。

  • condition: IEの条件付きコメントを指定します(例: `lt IE 9`)。これが指定されている場合、生成された`script`タグは条件付きコメントで囲まれます。これは主に、古いバージョンのIEブラウザをサポートするために役立ちます。

残りのオプションは、結果のscriptタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。

戻り値 文字列

生成された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);
}

            
label() public static メソッド

ラベルタグを生成します。

public static string label ( $content, $for null, $options = [] )
$content 文字列

ラベルテキスト。HTMLエンコードされません。そのため、画像タグなどのHTMLコードを渡すことができます。エンドユーザーからのものである場合は、XSS攻撃を防ぐためにencode()する必要があります。

$for 文字列|null

このラベルが関連付けられているHTML要素のID。nullの場合、「for」属性は生成されません。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたラベルタグ

                public static function label($content, $for = null, $options = [])
{
    $options['for'] = $for;
    return static::tag('label', $content, $options);
}

            
listBox() public static メソッド

リストボックスを生成します。

public static string listBox ( $name, $selection null, $items = [], $options = [] )
$name 文字列

入力名

$selection string|boolean|array|null

選択された値。単一選択の場合は文字列、複数選択の場合は配列。

$items 配列

オプションデータ項目。配列のキーはオプションの値、配列の値は対応するオプションのラベルです。配列はネストすることもできます(つまり、一部の配列の値も配列です)。各サブ配列に対して、ラベルがサブ配列に関連付けられたキーであるオプショングループが生成されます。データモデルのリストがある場合は、yii\helpers\ArrayHelper::map()を使用して、上記のように変換できます。

注記:値とラベルは、このメソッドによって自動的にHTMLエンコードされ、ラベル内の空白もHTMLエンコードされます。

$options 配列

名前と値のペアによるタグオプション。以下のオプションは特別に処理されます。

  • prompt: string、最初のオプションとして表示されるプロンプトテキスト。バージョン2.0.11以降、配列を使用して値をオーバーライドし、他のタグ属性を設定できます。

    ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']],
    
  • options: array、selectオプションタグの属性。配列のキーは有効なオプション値でなければならず、配列の値は対応するオプションタグの追加属性です。例えば、

    [
        'value1' => ['disabled' => true],
        'value2' => ['label' => 'value 2'],
    ];
    
  • groups: array、optgroupタグの属性。これは 'options' と同様の構造ですが、配列のキーは $items で指定された optgroup ラベルを表します。
  • unselect: string、オプションが選択されていない場合に送信される値。この属性が設定されている場合、隠しフィールドが生成され、複数モードでオプションが選択されていない場合でも、投稿されたunselect値を取得できます。
  • encodeSpaces: bool、オプションのプロンプトとオプションの値の空白を `&nbsp;` 文字でエンコードするかどうか。デフォルトは false です。
  • encode: bool、オプションのプロンプトとオプションの値の文字をエンコードするかどうか。デフォルトは `true` です。このオプションは 2.0.3 以降で使用できます。
  • strict: boolean、$selectionが配列で、この値がtrueの場合、$itemsのキーに対して厳密な比較が行われます。デフォルトはfalse。このオプションは2.0.37から利用可能です。

残りのオプションは、結果のタグの属性としてレンダリングされます。値はencode()を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。renderTagAttributes()で、属性のレンダリング方法の詳細を参照してください。

戻り値 文字列

生成されたリストボックスタグ

                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);
}

            
mailto() public static メソッド

mailtoハイパーリンクを生成します。

public static string mailto ( $text, $email null, $options = [] )
$text 文字列

リンク本文。HTMLエンコードされません。そのため、画像タグなどのHTMLコードを渡すことができます。エンドユーザーからの入力を受け取る場合は、XSS攻撃を防ぐためにencode() を検討する必要があります。

$email 文字列|null

メールアドレス。nullの場合、最初の引数(リンク本文)がメールアドレスとして扱われ、使用されます。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたmailtoリンク。

                public static function mailto($text, $email = null, $options = [])
{
    $options['href'] = 'mailto:' . ($email === null ? $text : $email);
    return static::tag('a', $text, $options);
}

            
ol() public static メソッド

順序付きリストを生成します。

public static string ol ( $items, $options = [] )
$items array|Traversable

リストを生成するためのアイテム。各アイテムは、1つのリストアイテムを生成します。`$options['encode']`が設定されていないか、trueの場合、アイテムは自動的にHTMLエンコードされます。

$options 配列

ラジオボタンリストのオプション(名前 => 設定)。以下のオプションがサポートされています。

  • encode: boolean、アイテムをHTMLエンコードするかどうか。デフォルトはtrue。このオプションは、`item`オプションが指定されている場合は無視されます。
  • itemOptions: array、`li`タグのHTML属性。このオプションは、`item`オプションが指定されている場合は無視されます。
  • item: callable、各リストアイテムを生成するために使用されるコールバック。このコールバックのシグネチャは次のようになります。

    function ($item, $index)
    

    ここで、`$index`は`$items`内の`$item`に対応する配列キーです。コールバックは、リストアイテムタグ全体を返す必要があります。

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成された順序付きリスト。`$items`が空の場合、空文字列が返されます。

                public static function ol($items, $options = [])
{
    $options['tag'] = 'ol';
    return static::ul($items, $options);
}

            
passwordInput() public static メソッド

パスワード入力フィールドを生成します。

public static string passwordInput ( $name, $value null, $options = [] )
$name 文字列

name属性。

$value 文字列|null

value属性。nullの場合、value属性は生成されません。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたパスワード入力タグ。

                public static function passwordInput($name, $value = null, $options = [])
{
    return static::input('password', $name, $value, $options);
}

            
radio() public static メソッド

ラジオボタン入力を生成します。

public static string radio ( $name, $checked false, $options = [] )
$name 文字列

name属性。

$checked ブール値

ラジオボタンをチェックするかどうか。

$options 配列

名前と値のペアで表されるタグオプション。booleanInput() で、受け入れられる属性の詳細を確認してください。

戻り値 文字列

生成されたラジオボタンタグ

                public static function radio($name, $checked = false, $options = [])
{
    return static::booleanInput('radio', $name, $checked, $options);
}

            
radioList() public static メソッド

ラジオボタンのリストを生成します。

ラジオボタンリストはチェックボックスリストに似ていますが、単一選択のみを許可します。

public static string radioList ( $name, $selection null, $items = [], $options = [] )
$name 文字列

各ラジオボタンのname属性。

$selection string|array|null

選択された値。単一選択の場合は文字列、複数選択の場合は配列。

$items 配列

ラジオボタンを生成するために使用されるデータアイテム。配列キーはラジオボタンの値で、配列値は対応するラベルです。

$options 配列

ラジオボタンリストコンテナタグのオプション(name => config)。次のオプションは特別に処理されます。

  • tag: string|false、コンテナ要素のタグ名。コンテナなしでラジオボタンをレンダリングする場合はfalse。 tag()も参照してください。
  • unselect: string、ラジオボタンのいずれも選択されていない場合に送信される値。このオプションを設定することで、隠し入力フィールドが生成されます。
  • disabled: boolean、unselectオプションによって生成された隠し入力フィールドを無効にするかどうか。デフォルトはfalse。このオプションはバージョン2.0.16から利用可能です。
  • encode: boolean、チェックボックスラベルをHTMLエンコードするかどうか。デフォルトはtrue。このオプションは、itemオプションが設定されている場合は無視されます。
  • strict: boolean、$selectionが配列で、この値がtrueの場合、$itemsのキーに対して厳密な比較が行われます。デフォルトはfalse。このオプションは2.0.37から利用可能です。
  • separator: string、項目を区切るHTMLコード。
  • itemOptions: array、radio()を使用してラジオボタンタグを生成するためのオプション。
  • item: callable、$items内の単一項目に対応するHTMLコードの生成をカスタマイズするために使用できるコールバック。このコールバックのシグネチャは次のようになります。

    function ($index, $label, $name, $checked, $value)
    

    ここで、`$index`はリスト全体におけるラジオボタンのゼロベースインデックス、`$label`はラジオボタンのラベル、`$name`、`$value`、`$checked`はそれぞれラジオボタン入力のname、value、チェック状態を表します。

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成されたラジオボタンリスト

                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);
}

            
removeCssClass() public static メソッド

指定されたオプションからCSSクラスを削除します。

addCssClass()も参照してください。

public static void removeCssClass ( &$options, $class )
$options 配列

変更するオプション。

$class 文字列|配列

削除する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);
            }
        }
    }
}

            
removeCssStyle() public static メソッド

指定されたCSSスタイルをHTMLオプションから削除します。

例:

Html::removeCssStyle($options, ['width', 'height']);

参照: addCssStyle().

public static void removeCssStyle ( &$options, $properties )
$options 配列

変更するHTMLオプション。

$properties 文字列|配列

削除する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);
    }
}

            
renderSelectOptions() public static メソッド

dropDownList()listBox() で使用できるオプションタグをレンダリングします。

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()を参照してください。

戻り値 文字列

生成されたリストオプション

                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(' ', '&nbsp;', $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(' ', '&nbsp;', $text);
            }
            $lines[] = static::tag('option', $text, $attrs);
        }
    }
    return implode("\n", $lines);
}

            
renderTagAttributes() public static メソッド

HTMLタグ属性をレンダリングします。

値がブール型の属性は、ブール属性として扱われます。

値が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エンコードされます。

戻り値 文字列

レンダリング結果。属性が空でない場合、先頭に空白文字が付いた文字列としてレンダリングされます(タグ名に直接追加できるようにするため)。属性がない場合は、空文字列が返されます。

                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;
}

            
resetButton() public static メソッド

リセットボタタグを生成します。

public static string resetButton ( $content 'Reset', $options = [] )
$content 文字列

ボタンタグ内に囲まれたコンテンツ。HTMLエンコードされません。そのため、画像タグなどのHTMLコードを渡すことができます。これがエンドユーザーからのものである場合、XSS攻撃を防ぐために encode() することを検討する必要があります。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたリセットボタンタグ

                public static function resetButton($content = 'Reset', $options = [])
{
    $options['type'] = 'reset';
    return static::button($content, $options);
}

            
resetInput() public static メソッド

リセット入力ボタンを生成します。

public static string resetInput ( $label 'Reset', $options = [] )
$label 文字列|null

value属性。nullの場合、value属性は生成されません。

$options 配列

ボタンタグの属性。encode()を使用してHTMLエンコードされます。値がnullの属性は無視され、返されるタグには含まれません。renderTagAttributes()で属性のレンダリング方法の詳細を参照してください。

戻り値 文字列

生成されたボタンタグ

                public static function resetInput($label = 'Reset', $options = [])
{
    $options['type'] = 'reset';
    $options['value'] = $label;
    return static::tag('input', '', $options);
}

            
script() public static メソッド

スクリプトタグを生成します。

public static string script ( $content, $options = [] )
$content 文字列

スクリプトの内容

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたscriptタグ。

                public static function script($content, $options = [])
{
    return static::tag('script', $content, $options);
}

            
setActivePlaceholder() protected static メソッド (バージョン 2.0.14以降で使用可能)

モデル属性ラベルからプレースホルダーを生成します。

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);
    }
}

            
style() public static メソッド

スタイルタグを生成します。

public static string style ( $content, $options = [] )
$content 文字列

スタイルの内容

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたスタイルタグ

                public static function style($content, $options = [])
{
    return static::tag('style', $content, $options);
}

            
submitButton() public static メソッド

送信ボタンタグを生成します。

送信ボタンなどのフォーム要素に名前を付ける際は注意が必要です。jQueryのドキュメントによると、submitlengthmethodなど、競合を引き起こす可能性のある予約済みの名前がいくつかあります。

public static string submitButton ( $content 'Submit', $options = [] )
$content 文字列

ボタンタグ内に囲まれたコンテンツ。HTMLエンコードされません。そのため、画像タグなどのHTMLコードを渡すことができます。これがエンドユーザーからのものである場合、XSS攻撃を防ぐために encode() することを検討する必要があります。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成された送信ボタンタグ

                public static function submitButton($content = 'Submit', $options = [])
{
    $options['type'] = 'submit';
    return static::button($content, $options);
}

            
submitInput() public static メソッド

送信入力ボタンを生成します。

送信ボタンなどのフォーム要素に名前を付ける際は注意が必要です。jQueryのドキュメントによると、submitlengthmethodなど、競合を引き起こす可能性のある予約済みの名前がいくつかあります。

public static string submitInput ( $label 'Submit', $options = [] )
$label 文字列|null

value属性。nullの場合、value属性は生成されません。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたボタンタグ

                public static function submitInput($label = 'Submit', $options = [])
{
    $options['type'] = 'submit';
    $options['value'] = $label;
    return static::tag('input', '', $options);
}

            
tag() public static メソッド

完全なHTMLタグを生成します。

参照

public static string tag ( $name, $content '', $options = [] )
$name 文字列|ブール値|null

タグ名。$nameがnullまたはfalseの場合、対応するコンテンツはタグなしでレンダリングされます。

$content 文字列

開始タグと終了タグの間に囲まれるコンテンツ。HTMLエンコードされません。エンドユーザーからの入力である場合は、XSS攻撃を防ぐためにencode() を検討してください。

$options 配列

名前と値のペアで表されるHTMLタグ属性(HTMLオプション)。これらは、結果のタグの属性としてレンダリングされます。encode() を使用して値はHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。

たとえば、['class' => 'my-class', 'target' => '_blank', 'value' => null] を使用すると、次のようにHTML属性がレンダリングされます。class="my-class" target="_blank"

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成された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>";
}

            
textInput() public static メソッド

テキスト入力フィールドを生成します。

public static string textInput ( $name, $value null, $options = [] )
$name 文字列

name属性。

$value 文字列|null

value属性。nullの場合、value属性は生成されません。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。値はencode() を使用してHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。属性のレンダリング方法の詳細については、renderTagAttributes() を参照してください。

戻り値 文字列

生成されたテキスト入力タグ

                public static function textInput($name, $value = null, $options = [])
{
    return static::input('text', $name, $value, $options);
}

            
textarea() public static メソッド

テキストエリア入力を生成します。

public static string textarea ( $name, $value '', $options = [] )
$name 文字列

入力名

$value 文字列

入力値。encode() を使用してエンコードされます。

$options 配列

名前と値のペアで表されるタグオプション。これらは、結果のタグの属性としてレンダリングされます。encode() を使用して値はHTMLエンコードされます。値がnullの場合、対応する属性はレンダリングされません。renderTagAttributes() を参照して、属性のレンダリング方法の詳細を確認してください。以下の特別なオプションが認識されます。

  • doubleEncode: $value のHTMLエンティティを二重にエンコードするかどうか。false の場合、$value のHTMLエンティティはさらにエンコードされません。このオプションはバージョン2.0.11から利用可能です。
戻り値 文字列

生成されたテキストエリアタグ

                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);
}

            
ul() public static メソッド

順序なしリストを生成します。

public static string ul ( $items, $options = [] )
$items array|Traversable

リストを生成するためのアイテム。各アイテムは、1つのリストアイテムを生成します。`$options['encode']`が設定されていないか、trueの場合、アイテムは自動的にHTMLエンコードされます。

$options 配列

ラジオボタンリストのオプション(名前 => 設定)。以下のオプションがサポートされています。

  • encode: boolean、アイテムをHTMLエンコードするかどうか。デフォルトはtrue。このオプションは、`item`オプションが指定されている場合は無視されます。
  • separator: string、アイテムを区切るHTMLコード。デフォルトは単純な改行 ("\n") です。このオプションはバージョン2.0.7から利用可能です。
  • itemOptions: array、`li`タグのHTML属性。このオプションは、`item`オプションが指定されている場合は無視されます。
  • item: callable、各リストアイテムを生成するために使用されるコールバック。このコールバックのシグネチャは次のようになります。

    function ($item, $index)
    

    ここで、`$index`は`$items`内の`$item`に対応する配列キーです。コールバックは、リストアイテムタグ全体を返す必要があります。

属性のレンダリング方法の詳細については、renderTagAttributes()を参照してください。

戻り値 文字列

生成された順序なしリスト。$items が空の場合、空のリストタグが返されます。

                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
    );
}