1 フォロワー

クラス yii\data\ActiveDataFilter

継承yii\data\ActiveDataFilter » yii\data\DataFilter » yii\base\Model » yii\base\Component » yii\base\BaseObject
実装ArrayAccessIteratorAggregateyii\base\Arrayableyii\base\Configurableyii\base\StaticInstanceInterface
使用するトレイトyii\base\ArrayableTraityii\base\StaticInstanceTrait
利用可能なバージョン2.0.13
ソースコード https://github.com/yiisoft/yii2/blob/master/framework/data/ActiveDataFilter.php

ActiveDataFilter は、yii\db\QueryInterface::where() に適した形式でフィルタリング条件を構成できます。

こちらも参照してください yii\data\DataFilter

公開プロパティ

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

プロパティ 説明 定義元
$activeValidators yii\validators\Validator[] 現在の$scenarioに適用可能なバリデータ。 yii\base\Model
$attributeMap array 検索条件で使用される実際の属性名。形式は [filterAttribute => actualAttribute] です。 yii\data\DataFilter
$attributes array 属性値 (名前 => 値)。 yii\base\Model
$behaviors yii\base\Behavior[] このコンポーネントにアタッチされたビヘイビアのリスト。 yii\base\Component
$conditionBuilders array フィルタリング条件のキーワードをビルドメソッドにマッピングします。 yii\data\ActiveDataFilter
$conditionValidators array フィルタ条件のキーワードを検証メソッドにマッピングします。 yii\data\DataFilter
$errorMessages array [errorKey => message]形式のエラーメッセージ。 yii\data\DataFilter
$errors array すべての属性、または指定された属性のエラー。 yii\base\Model
$filter mixed 生のフィルタ値。 yii\data\DataFilter
$filterAttributeLabel string $filterAttributeNameで指定されたフィルタ属性のラベル。 yii\data\DataFilter
$filterAttributeName string フィルタ値を処理する属性の名前。 yii\data\DataFilter
$filterControls array フィルタで使用できるキーワードまたは式。 yii\data\DataFilter
$firstErrors array 最初のエラー。 yii\base\Model
$iterator ArrayIterator リスト内のアイテムをトラバースするためのイテレータ。 yii\base\Model
$multiValueOperators array 複数の値を受け入れる必要がある演算子のキーワードのリスト。 yii\data\DataFilter
$nullValue string 後者が使用できない場合の、リテラルnullの代わりにnullを表すもの。 yii\data\DataFilter
$operatorTypes array 各演算子ごとにサポートされている検索属性タイプのリストを指定します。 yii\data\DataFilter
$queryOperatorMap array yii\db\QueryInterface::where()で使用される演算子へのフィルタリング演算子のマッピング。 yii\data\ActiveDataFilter
$scenario string このモデルが存在するシナリオ。 yii\base\Model
$searchAttributeTypes array 検索属性タイプのマップ。 yii\data\DataFilter
$searchModel yii\base\Model モデルインスタンス。 yii\data\DataFilter
$validators ArrayObject|yii\validators\Validator[] モデルで宣言されているすべてのバリデータ。 yii\base\Model

公開メソッド

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

メソッド 説明 定義元
__call() クラスメソッドではない名前付きメソッドを呼び出します。 yii\base\Component
__clone() このメソッドは、既存のオブジェクトをクローンしてオブジェクトが作成された後に呼び出されます。 yii\base\Model
__construct() コンストラクタ。 yii\base\BaseObject
__get() コンポーネントプロパティの値を返します。 yii\data\DataFilter
__isset() プロパティが設定されているかどうか(つまり、定義されていてnullではないかどうか)を確認します。 yii\data\DataFilter
__set() コンポーネントプロパティの値を設定します。 yii\data\DataFilter
__unset() コンポーネントプロパティをnullに設定します。 yii\data\DataFilter
activeAttributes() 現在のシナリオで検証の対象となる属性名を返します。 yii\base\Model
addError() 指定された属性に新しいエラーを追加します。 yii\base\Model
addErrors() エラーのリストを追加します。 yii\base\Model
afterValidate() このメソッドは、検証が終了した後に呼び出されます。 yii\base\Model
attachBehavior() このコンポーネントにビヘイビアをアタッチします。 yii\base\Component
attachBehaviors() コンポーネントにビヘイビアのリストをアタッチします。 yii\base\Component
attributeHints() 属性ヒントを返します。 yii\base\Model
attributeLabels() 属性ラベルを返します。 yii\data\DataFilter
attributes() 属性名のリストを返します。 yii\data\DataFilter
beforeValidate() このメソッドは、検証が開始する前に呼び出されます。 yii\base\Model
behaviors() このコンポーネントが動作する必要があるビヘイビアのリストを返します。 yii\base\Component
build() $filter値から実際のフィルタ仕様を構築します。 yii\data\DataFilter
canGetProperty() プロパティを読み取ることができるかどうかを示す値を返します。 yii\data\DataFilter
canSetProperty() プロパティを設定できるかどうかを示す値を返します。 yii\data\DataFilter
className() このクラスの完全修飾名を返します。 yii\base\BaseObject
clearErrors() すべての属性または単一の属性のエラーを削除します。 yii\base\Model
createValidators() rules()で指定された検証ルールに基づいて、バリデータオブジェクトを作成します。 yii\base\Model
detachBehavior() コンポーネントからビヘイビアをデタッチします。 yii\base\Component
detachBehaviors() コンポーネントからすべてのビヘイビアをデタッチします。 yii\base\Component
ensureBehaviors() behaviors()で宣言されたビヘイビアがこのコンポーネントにアタッチされていることを確認します。 yii\base\Component
extraFields() toArray()によってさらに展開され、返されるフィールドのリストを返します。 yii\base\ArrayableTrait
fields() 特定のフィールドが指定されていない場合、toArray()によってデフォルトで返されるべきフィールドのリストを返します。 yii\base\ArrayableTrait
formName() このモデルクラスが使用するフォーム名を返します。 yii\data\DataFilter
generateAttributeLabel() 与えられた属性名に基づいて、ユーザーフレンドリーな属性ラベルを生成します。 yii\base\Model
getActiveValidators() 現在の$scenarioに適用可能なバリデータ(検証子)を返します。 yii\base\Model
getAttributeHint() 指定された属性のテキストヒントを返します。 yii\base\Model
getAttributeLabel() 指定された属性のテキストラベルを返します。 yii\base\Model
getAttributes() 属性値を返します。 yii\base\Model
getBehavior() 名前付きのビヘイビアオブジェクトを返します。 yii\base\Component
getBehaviors() このコンポーネントにアタッチされているすべてのビヘイビアを返します。 yii\base\Component
getErrorMessages() yii\data\DataFilter
getErrorSummary() すべての属性のエラーを一次元配列として返します。 yii\base\Model
getErrors() すべての属性または単一の属性のエラーを返します。 yii\base\Model
getFilter() yii\data\DataFilter
getFirstError() 指定された属性の最初のエラーを返します。 yii\base\Model
getFirstErrors() モデル内の各属性の最初のエラーを返します。 yii\base\Model
getIterator() モデル内の属性をトラバースするためのイテレータを返します。 yii\base\Model
getScenario() このモデルが使用されているシナリオを返します。 yii\base\Model
getSearchAttributeTypes() yii\data\DataFilter
getSearchModel() yii\data\DataFilter
getValidators() rules()で宣言されているすべてのバリデータ(検証子)を返します。 yii\base\Model
hasErrors() バリデーションエラーがあるかどうかを示す値を返します。 yii\base\Model
hasEventHandlers() 名前付きイベントにハンドラーがアタッチされているかどうかを示す値を返します。 yii\base\Component
hasMethod() メソッドが定義されているかどうかを示す値を返します。 yii\base\Component
hasProperty() このコンポーネントにプロパティが定義されているかどうかを示す値を返します。 yii\base\Component
init() オブジェクトを初期化します。 yii\base\BaseObject
instance() メタ情報を取得するために使用できる、静的クラスインスタンスを返します。 yii\base\StaticInstanceTrait
isAttributeActive() 現在のシナリオで属性がアクティブかどうかを示す値を返します。 yii\base\Model
isAttributeRequired() 属性が必須かどうかを示す値を返します。 yii\base\Model
isAttributeSafe() 属性が大量代入に対して安全かどうかを示す値を返します。 yii\base\Model
load() 入力データでモデルを設定します。 yii\base\Model
loadMultiple() エンドユーザーからのデータを使用して、一連のモデルを設定します。 yii\base\Model
normalize() $filterControls$attributeMapに従って、生のキーを置き換えることで、フィルタ値を正規化します。 yii\data\DataFilter
off() このコンポーネントから既存のイベントハンドラーをデタッチします。 yii\base\Component
offsetExists() 指定されたオフセットに要素があるかどうかを返します。 yii\base\Model
offsetGet() 指定されたオフセットの要素を返します。 yii\base\Model
offsetSet() 指定されたオフセットに要素を設定します。 yii\base\Model
offsetUnset() 指定されたオフセットの要素値をnullに設定します。 yii\base\Model
on() イベントにイベントハンドラーをアタッチします。 yii\base\Component
onUnsafeAttribute() 安全でない属性が大量に代入されている場合に呼び出されるメソッドです。 yii\base\Model
rules() 属性のバリデーションルール(検証ルール)を返します。 yii\data\DataFilter
safeAttributes() 現在のシナリオで大量に代入しても安全な属性名を返します。 yii\base\Model
scenarios() シナリオと対応するアクティブな属性のリストを返します。 yii\base\Model
setAttributes() 大量に属性値を設定します。 yii\base\Model
setErrorMessages() 無効なフィルタ構造に対応するエラーメッセージのリストを`[errorKey => message]`の形式で設定します。 yii\data\DataFilter
setFilter() yii\data\DataFilter
setScenario() モデルのシナリオを設定します。 yii\base\Model
setSearchAttributeTypes() yii\data\DataFilter
setSearchModel() yii\data\DataFilter
toArray() モデルを配列に変換します。 yii\base\ArrayableTrait
trigger() イベントをトリガーします。 yii\base\Component
validate() データのバリデーション(検証)を実行します。 yii\base\Model
validateFilter() フィルタ条件の仕様と一致するようにフィルタ属性値を検証します。 yii\data\DataFilter
validateMultiple() 複数のモデルを検証します。 yii\base\Model

プロテクトされたメソッド

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

メソッド 説明 定義元
buildAttributeCondition() 特定の属性の検索条件を構築します。 yii\data\ActiveDataFilter
buildBlockCondition() 単一の条件からなるブロック条件を構築します。 yii\data\ActiveDataFilter
buildCondition() yii\data\ActiveDataFilter
buildConjunctionCondition() 複数の独立した条件からなる複合条件を構築します。 yii\data\ActiveDataFilter
buildInternal() 実際のフィルタ構築を実行します。 yii\data\ActiveDataFilter
buildOperatorCondition() 演算子条件を構築します。 yii\data\ActiveDataFilter
defaultErrorMessages() $errorMessagesのデフォルト値を返します。 yii\data\DataFilter
detectSearchAttributeType() 与えられたバリデータ(検証子)から属性タイプを検出します。 yii\data\DataFilter
detectSearchAttributeTypes() $searchModelのバリデーションルール(検証ルール)から$searchAttributeTypesのデフォルト値を構成します。 yii\data\DataFilter
extractFieldsFor() 指定されたルートフィールドに対して、フィールドコレクションからネストされたフィールドを抽出します。ネストされたフィールドはドット(.)で区切られます。例:「item.id」この例では「id」が抽出されます。 yii\base\ArrayableTrait
extractRootFields() ネストされたフィールドからルートフィールド名を抽出します。 yii\base\ArrayableTrait
filterAttributeValue() 属性値フィルタがあれば適用して、$searchModelの範囲内で属性値を検証します。 yii\data\DataFilter
parseErrorMessage() メッセージキーで指定された$errorMessagesからのメッセージの内容を解析します。 yii\data\DataFilter
resolveFields() toArray()によって返されるフィールドを決定します。 yii\base\ArrayableTrait
validateAttributeCondition() 特定の属性の検索条件を検証します。 yii\data\DataFilter
validateAttributeValue() modelの範囲内で属性値を検証します。 yii\data\DataFilter
validateBlockCondition() 単一の条件からなるブロック条件を検証します。 yii\data\DataFilter
validateCondition() フィルタ条件を検証します。 yii\data\DataFilter
validateConjunctionCondition() 複数の独立した条件からなる複合条件を検証します。 yii\data\DataFilter
validateOperatorCondition() 演算子条件を検証します。 yii\data\DataFilter

イベント

継承されたイベントを非表示

イベント 説明 定義元
EVENT_AFTER_VALIDATE yii\base\Event validate()の最後に発生するイベント yii\base\Model
EVENT_BEFORE_VALIDATE yii\base\ModelEvent validate()の最初に発生するイベント。 yii\base\Model

定数

継承された定数を非表示

定数 説明 定義元
SCENARIO_DEFAULT 'default' デフォルトシナリオの名前。 yii\base\Model
TYPE_ARRAY 'array' yii\data\DataFilter
TYPE_BOOLEAN 'boolean' yii\data\DataFilter
TYPE_DATE 'date' yii\data\DataFilter
TYPE_DATETIME 'datetime' yii\data\DataFilter
TYPE_FLOAT 'float' yii\data\DataFilter
TYPE_INTEGER 'integer' yii\data\DataFilter
TYPE_STRING 'string' yii\data\DataFilter
TYPE_TIME 'time' yii\data\DataFilter

プロパティの詳細

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

$conditionBuilders public property

フィルタリング条件キーワードを構築メソッドにマッピングします。これらのメソッドは、buildCondition()によって実際のフィルタリング条件を構築するために使用されます。特定の条件ビルダーは、PHPコールバックを使用して指定できます。例:

[
    'XOR' => function (string $operator, mixed $condition) {
        //return array;
    },
    'LIKE' => function (string $operator, mixed $condition, string $attribute) {
        //return array;
    },
]
public array $conditionBuilders = [
    
'AND' => 'buildConjunctionCondition',
    
'OR' => 'buildConjunctionCondition',
    
'NOT' => 'buildBlockCondition',
    
'<' => 'buildOperatorCondition',
    
'>' => 'buildOperatorCondition',
    
'<=' => 'buildOperatorCondition',
    
'>=' => 'buildOperatorCondition',
    
'=' => 'buildOperatorCondition',
    
'!=' => 'buildOperatorCondition',
    
'IN' => 'buildOperatorCondition',
    
'NOT IN' => 'buildOperatorCondition',
    
'LIKE' => 'buildOperatorCondition',
]
$queryOperatorMap public property

yii\db\QueryInterface::where()で使用される演算子にフィルタリング演算子をマッピングします。形式は`[filterOperator => queryOperator]`です。特定の演算子キーワードがマップに表示されない場合、そのまま使用されます。

通常、マップは空のままにしておくことができます。これは、フィルタ演算子の名前がyii\db\QueryInterface::where()で使用されているものと一致するためです。ただし、特別なケースでは調整が必要になる場合があります。たとえば、PostgreSQLを使用する場合、次のマップを設定することをお勧めします。

[
    'LIKE' => 'ILIKE'
]

メソッドの詳細

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

__call() publicメソッド

定義場所: yii\base\Component::__call()

クラスメソッドではない名前付きメソッドを呼び出します。

このメソッドは、アタッチされたビヘイビアに指定されたメソッドがあるかどうかをチェックし、あれば実行します。

これはPHPのマジックメソッドであり、未知のメソッドが呼び出された際に暗黙的に呼び出されるため、直接呼び出さないでください。

public mixed __call ( $name, $params )
$name string

メソッド名

$params array

メソッドパラメータ

戻り値 mixed

メソッドの戻り値

例外 yii\base\UnknownMethodException

未知のメソッドを呼び出した場合

                public function __call($name, $params)
{
    $this->ensureBehaviors();
    foreach ($this->_behaviors as $object) {
        if ($object->hasMethod($name)) {
            return call_user_func_array([$object, $name], $params);
        }
    }
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            
__clone() publicメソッド

定義場所: yii\base\Model::__clone()

このメソッドは、既存のオブジェクトをクローンしてオブジェクトが作成された後に呼び出されます。

ビヘイビアは古いオブジェクトにアタッチされているため、すべてのビヘイビアを削除します。

public void __clone ( )

                public function __clone()
{
    parent::__clone();
    $this->_errors = null;
    $this->_validators = null;
}

            
__construct() publicメソッド

定義場所: yii\base\BaseObject::__construct()

コンストラクタ。

デフォルトの実装では、次の2つのことを行います。

  • 指定された設定$configを使用してオブジェクトを初期化します。
  • init()を呼び出します。

このメソッドを子クラスでオーバーライドする場合は、

  • コンストラクタの最後のパラメータが、ここにある$configのような設定配列であることをお勧めします。
  • コンストラクタの最後に親の実装を呼び出してください。
public void __construct ( $config = [] )
$config array

オブジェクトのプロパティを初期化するために使用される名前と値のペア

                public function __construct($config = [])
{
    if (!empty($config)) {
        Yii::configure($this, $config);
    }
    $this->init();
}

            
__get() publicメソッド

定義場所: yii\data\DataFilter::__get()

コンポーネントプロパティの値を返します。

このメソッドは、以下の順序でチェックし、それに応じて動作します。

  • ゲッターによって定義されたプロパティ: ゲッターの結果を返します。
  • ビヘイビアのプロパティ: ビヘイビアのプロパティ値を返します。

これはPHPのマジックメソッドであり、`$value = $component->property;`を実行した際に暗黙的に呼び出されるため、直接呼び出さないでください。

public mixed __get ( $name )
$name string

プロパティ名

戻り値 mixed

プロパティ値またはビヘイビアのプロパティの値

例外 yii\base\UnknownPropertyException

プロパティが定義されていない場合

例外 yii\base\InvalidCallException

プロパティが書き込み専用の場合。

                public function __get($name)
{
    if ($name === $this->filterAttributeName) {
        return $this->getFilter();
    }
    return parent::__get($name);
}

            
__isset() publicメソッド

定義場所: yii\data\DataFilter::__isset()

プロパティが設定されているかどうか(つまり、定義されていてnullではないかどうか)を確認します。

このメソッドは、以下の順序でチェックし、それに応じて動作します。

  • セッターによって定義されたプロパティ: プロパティが設定されているかどうかを返します。
  • ビヘイビアのプロパティ: プロパティが設定されているかどうかを返します。
  • 存在しないプロパティには`false`を返します。

これはPHPのマジックメソッドであり、`isset($component->property)`を実行した際に暗黙的に呼び出されるため、直接呼び出さないでください。

public boolean __isset ( $name )
$name string

プロパティ名またはイベント名

戻り値 boolean

指定されたプロパティが設定されているかどうか

                public function __isset($name)
{
    if ($name === $this->filterAttributeName) {
        return $this->getFilter() !== null;
    }
    return parent::__isset($name);
}

            
__set() publicメソッド

定義場所: yii\data\DataFilter::__set()

コンポーネントプロパティの値を設定します。

このメソッドは、以下の順序でチェックし、それに応じて動作します。

  • セッターによって定義されたプロパティ: プロパティ値を設定します。
  • "on xyz"形式のイベント: "xyz"イベントにハンドラをアタッチします。
  • "as xyz"形式のビヘイビア: "xyz"という名前のビヘイビアをアタッチします。
  • ビヘイビアのプロパティ: ビヘイビアのプロパティ値を設定します。

これはPHPのマジックメソッドであり、`$component->property = $value;`を実行した際に暗黙的に呼び出されるため、直接呼び出さないでください。

public void __set ( $name, $value )
$name string

プロパティ名またはイベント名

$value mixed

プロパティ値

例外 yii\base\UnknownPropertyException

プロパティが定義されていない場合

例外 yii\base\InvalidCallException

プロパティが読み取り専用の場合。

                public function __set($name, $value)
{
    if ($name === $this->filterAttributeName) {
        $this->setFilter($value);
    } else {
        parent::__set($name, $value);
    }
}

            
__unset() publicメソッド

定義場所: yii\data\DataFilter::__unset()

コンポーネントプロパティをnullに設定します。

このメソッドは、以下の順序でチェックし、それに応じて動作します。

  • セッターによって定義されたプロパティ: プロパティ値をnullに設定します。
  • ビヘイビアのプロパティ: プロパティ値をnullに設定します。

これはPHPのマジックメソッドであり、`unset($component->property)`を実行した際に暗黙的に呼び出されるため、直接呼び出さないでください。

public void __unset ( $name )
$name string

プロパティ名

例外 yii\base\InvalidCallException

プロパティが読み取り専用の場合。

                public function __unset($name)
{
    if ($name === $this->filterAttributeName) {
        $this->setFilter(null);
    } else {
        parent::__unset($name);
    }
}

            
activeAttributes() publicメソッド

定義場所: yii\base\Model::activeAttributes()

現在のシナリオで検証の対象となる属性名を返します。

public string[] activeAttributes ( )
戻り値 string[]

安全な属性名

                public function activeAttributes()
{
    $scenario = $this->getScenario();
    $scenarios = $this->scenarios();
    if (!isset($scenarios[$scenario])) {
        return [];
    }
    $attributes = array_keys(array_flip($scenarios[$scenario]));
    foreach ($attributes as $i => $attribute) {
        if (strncmp($attribute, '!', 1) === 0) {
            $attributes[$i] = substr($attribute, 1);
        }
    }
    return $attributes;
}

            
addError() publicメソッド

定義場所: yii\base\Model::addError()

指定された属性に新しいエラーを追加します。

public void addError ( $attribute, $error '' )
$attribute string

属性名

$error string

新しいエラーメッセージ

                public function addError($attribute, $error = '')
{
    $this->_errors[$attribute][] = $error;
}

            
addErrors() public メソッド (バージョン 2.0.2 から利用可能)

定義位置: yii\base\Model::addErrors()

エラーのリストを追加します。

public void addErrors ( array $items )
$items array

エラーのリスト。配列のキーは属性名でなければなりません。配列の値はエラーメッセージです。属性に複数のエラーがある場合、それらのエラーは配列として指定する必要があります。getErrors() の結果をこのパラメータの値として使用できます。

                public function addErrors(array $items)
{
    foreach ($items as $attribute => $errors) {
        if (is_array($errors)) {
            foreach ($errors as $error) {
                $this->addError($attribute, $error);
            }
        } else {
            $this->addError($attribute, $errors);
        }
    }
}

            
afterValidate() public メソッド

定義位置: yii\base\Model::afterValidate()

このメソッドは、検証が終了した後に呼び出されます。

デフォルトの実装では、afterValidate イベントを発生させます。検証後の後処理を行うために、このメソッドをオーバーライドできます。イベントが発生するように、親の実装を呼び出すようにしてください。

public void afterValidate ( )

                public function afterValidate()
{
    $this->trigger(self::EVENT_AFTER_VALIDATE);
}

            
attachBehavior() public メソッド

定義位置: yii\base\Component::attachBehavior()

このコンポーネントにビヘイビアをアタッチします。

このメソッドは、指定された設定に基づいてビヘイビアオブジェクトを作成します。その後、yii\base\Behavior::attach() メソッドを呼び出すことで、ビヘイビアオブジェクトがこのコンポーネントにアタッチされます。

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

public yii\base\Behavior attachBehavior ( $name, $behavior )
$name string

ビヘイビアの名前。

$behavior string|array|yii\base\Behavior

ビヘイビアの設定。次のいずれかになります。

  • yii\base\Behavior オブジェクト
  • ビヘイビアクラスを指定する文字列
  • ビヘイビアオブジェクトを作成するために Yii::createObject() に渡されるオブジェクト設定配列。
戻り値 yii\base\Behavior

ビヘイビアオブジェクト

                public function attachBehavior($name, $behavior)
{
    $this->ensureBehaviors();
    return $this->attachBehaviorInternal($name, $behavior);
}

            
attachBehaviors() public メソッド

定義位置: yii\base\Component::attachBehaviors()

コンポーネントにビヘイビアのリストをアタッチします。

各ビヘイビアは名前でインデックス付けされ、yii\base\Behavior オブジェクト、ビヘイビアクラスを指定する文字列、またはビヘイビアを作成するための設定配列でなければなりません。

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

public void attachBehaviors ( $behaviors )
$behaviors array

コンポーネントにアタッチされるビヘイビアのリスト。

                public function attachBehaviors($behaviors)
{
    $this->ensureBehaviors();
    foreach ($behaviors as $name => $behavior) {
        $this->attachBehaviorInternal($name, $behavior);
    }
}

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

定義位置: yii\base\Model::attributeHints()

属性ヒントを返します。

属性ヒントは主に表示目的で使用されます。例えば、属性isPublicに対して、ヒントログインしていないユーザーに対して投稿を表示するかどうかを宣言することで、属性の意味に関するユーザーフレンドリーな説明を提供し、エンドユーザーに表示することができます。

ラベルとは異なり、明示的な宣言がない場合はヒントは生成されません。

親クラスで定義されたヒントを継承するには、子クラスはarray_merge()などの関数を使用して親のヒントと子のヒントをマージする必要があります。

public array attributeHints ( )
戻り値 array

属性ヒント (名前 => ヒント)

                public function attributeHints()
{
    return [];
}

            
attributeLabels() public メソッド

定義位置: yii\data\DataFilter::attributeLabels()

属性ラベルを返します。

属性ラベルは主に表示目的で使用されます。例えば、属性firstNameに対して、よりユーザーフレンドリーでエンドユーザーに表示できるラベルFirst Nameを宣言できます。

デフォルトでは、属性ラベルはgenerateAttributeLabel()を使用して生成されます。このメソッドを使用すると、属性ラベルを明示的に指定できます。

親クラスで定義されたラベルを継承するには、子クラスはarray_merge()などの関数を使用して親のラベルと子のラベルをマージする必要があります。

public array attributeLabels ( )
戻り値 array

属性ラベル (名前 => ラベル)

                public function attributeLabels()
{
    return [
        $this->filterAttributeName => $this->filterAttributeLabel,
    ];
}

            
attributes() public メソッド

定義位置: yii\data\DataFilter::attributes()

属性名のリストを返します。

デフォルトでは、このメソッドはクラスのすべてのpublicな非staticプロパティを返します。デフォルトの動作を変更するには、このメソッドをオーバーライドできます。

public string[] attributes ( )
戻り値 string[]

属性名のリスト。

                public function attributes()
{
    return [
        $this->filterAttributeName,
    ];
}

            
beforeValidate() public メソッド

定義位置: yii\base\Model::beforeValidate()

このメソッドは、検証が開始する前に呼び出されます。

デフォルトの実装では、beforeValidate イベントを発生させます。検証前の予備チェックを行うために、このメソッドをオーバーライドできます。イベントが発生するように、親の実装を呼び出すようにしてください。

public boolean beforeValidate ( )
戻り値 boolean

検証を実行するかどうか。デフォルトはtrueです。falseを返すと、検証は停止し、モデルは無効とみなされます。

                public function beforeValidate()
{
    $event = new ModelEvent();
    $this->trigger(self::EVENT_BEFORE_VALIDATE, $event);
    return $event->isValid;
}

            
behaviors() public メソッド

定義位置: yii\base\Component::behaviors()

このコンポーネントが動作する必要があるビヘイビアのリストを返します。

子クラスは、このメソッドをオーバーライドして、動作させたいビヘイビアを指定できます。

このメソッドの戻り値は、ビヘイビア名でインデックス付けされたビヘイビアオブジェクトまたは設定の配列でなければなりません。ビヘイビア設定は、ビヘイビアクラスを指定する文字列、または以下の構造の配列のいずれかです。

'behaviorName' => [
    'class' => 'BehaviorClass',
    'property1' => 'value1',
    'property2' => 'value2',
]

ビヘイビアクラスはyii\base\Behaviorを拡張する必要があります。ビヘイビアは名前付きでまたは匿名でアタッチできます。配列キーとして名前を使用する場合、この名前を使用して、getBehavior()を使用して後でビヘイビアを取得したり、detachBehavior()を使用してデタッチしたりできます。匿名ビヘイビアは取得またはデタッチできません。

このメソッドで宣言されたビヘイビアは、コンポーネントに自動的に(オンデマンドで)アタッチされます。

public array behaviors ( )
戻り値 array

ビヘイビア設定。

                public function behaviors()
{
    return [];
}

            
build() public メソッド

定義されている場所: yii\data\DataFilter::build()

$filter値から実際のフィルタ仕様を構築します。

public mixed|false build ( $runValidation true )
$runValidation boolean

フィルタを構築する前に検証を実行するかどうか(validate() を呼び出す)を指定します。デフォルトは true です。検証に失敗した場合、フィルタは構築されず、このメソッドは false を返します。

戻り値 mixed|false

構築された実際のフィルタ値、または検証に失敗した場合は false

                public function build($runValidation = true)
{
    if ($runValidation && !$this->validate()) {
        return false;
    }
    return $this->buildInternal();
}

            
buildAttributeCondition() protected メソッド

特定の属性の検索条件を構築します。

protected array buildAttributeCondition ( $attribute, $condition )
$attribute string

検索属性名。

$condition mixed

検索条件。

戻り値 array

実際の条件。

                protected function buildAttributeCondition($attribute, $condition)
{
    if (is_array($condition)) {
        $parts = [];
        foreach ($condition as $operator => $value) {
            if (isset($this->operatorTypes[$operator])) {
                if (isset($this->conditionBuilders[$operator])) {
                    $method = $this->conditionBuilders[$operator];
                    if (is_string($method)) {
                        $callback = [$this, $method];
                    } else {
                        $callback = $method;
                    }
                    $parts[] = $callback($operator, $value, $attribute);
                } else {
                    $parts[] = $this->buildOperatorCondition($operator, $value, $attribute);
                }
            }
        }
        if (!empty($parts)) {
            if (count($parts) > 1) {
                return array_merge(['AND'], $parts);
            }
            return array_shift($parts);
        }
    }
    return [$attribute => $this->filterAttributeValue($attribute, $condition)];
}

            
buildBlockCondition() protected メソッド

単一の条件からなるブロック条件を構築します。

notなどの演算子を処理します。

protected array buildBlockCondition ( $operator, $condition )
$operator string

演算子キーワード。

$condition mixed

生の条件。

戻り値 array

実際の条件。

                protected function buildBlockCondition($operator, $condition)
{
    if (isset($this->queryOperatorMap[$operator])) {
        $operator = $this->queryOperatorMap[$operator];
    }
    return [
        $operator,
        $this->buildCondition($condition),
    ];
}

            
buildCondition() protected メソッド

protected array buildCondition ( $condition )
$condition array
戻り値 array

構築された条件。

                protected function buildCondition($condition)
{
    $parts = [];
    foreach ($condition as $key => $value) {
        if (isset($this->conditionBuilders[$key])) {
            $method = $this->conditionBuilders[$key];
            if (is_string($method)) {
                $callback = [$this, $method];
            } else {
                $callback = $method;
            }
        } else {
            $callback = [$this, 'buildAttributeCondition'];
        }
        $parts[] = $callback($key, $value);
    }
    if (!empty($parts)) {
        if (count($parts) > 1) {
            array_unshift($parts, 'AND');
        } else {
            $parts = array_shift($parts);
        }
    }
    return $parts;
}

            
buildConjunctionCondition() protected メソッド

複数の独立した条件からなる複合条件を構築します。

andorなどの演算子を処理します。

protected array buildConjunctionCondition ( $operator, $condition )
$operator string

演算子キーワード。

$condition mixed

生の条件。

戻り値 array

実際の条件。

                protected function buildConjunctionCondition($operator, $condition)
{
    if (isset($this->queryOperatorMap[$operator])) {
        $operator = $this->queryOperatorMap[$operator];
    }
    $result = [$operator];
    foreach ($condition as $part) {
        $result[] = $this->buildCondition($part);
    }
    return $result;
}

            
buildInternal() protected メソッド

実際のフィルタ構築を実行します。

デフォルトでは、このメソッドはnormalize()の結果を返します。子クラスはこのメソッドをオーバーライドして、より具体的な実装を提供できます。

protected mixed buildInternal ( )
戻り値 mixed

構築された実際のフィルタ値。

                protected function buildInternal()
{
    $filter = $this->normalize(false);
    if (empty($filter)) {
        return [];
    }
    return $this->buildCondition($filter);
}

            
buildOperatorCondition() protected メソッド

演算子条件を構築します。

protected array buildOperatorCondition ( $operator, $condition, $attribute )
$operator string

演算子キーワード。

$condition mixed

属性条件。

$attribute string

属性名。

戻り値 array

実際の条件。

                protected function buildOperatorCondition($operator, $condition, $attribute)
{
    if (isset($this->queryOperatorMap[$operator])) {
        $operator = $this->queryOperatorMap[$operator];
    }
    return [$operator, $attribute, $this->filterAttributeValue($attribute, $condition)];
}

            
canGetProperty() public メソッド

定義されている場所: yii\data\DataFilter::canGetProperty()

プロパティを読み取ることができるかどうかを示す値を返します。

プロパティは、以下の場合に読み取ることができます。

  • クラスに、指定された名前と関連付けられたゲッターメソッドがある場合(この場合、プロパティ名はケースインセンシティブです)。
  • クラスに、指定された名前のメンバ変数がある場合($checkVars が true の場合)。
  • アタッチされたビヘイビアに、指定された名前の読み取り可能なプロパティがある場合($checkBehaviors が true の場合)。
public boolean canGetProperty ( $name, $checkVars true, $checkBehaviors true )
$name string

プロパティ名

$checkVars boolean

メンバ変数をプロパティとして扱うかどうか

$checkBehaviors boolean

ビヘイビアのプロパティをこのコンポーネントのプロパティとして扱うかどうか

戻り値 boolean

プロパティを読み取ることができるかどうか

                public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
{
    if ($name === $this->filterAttributeName) {
        return true;
    }
    return parent::canGetProperty($name, $checkVars, $checkBehaviors);
}

            
canSetProperty() public メソッド

定義されている場所: yii\data\DataFilter::canSetProperty()

プロパティを設定できるかどうかを示す値を返します。

プロパティは、以下の場合に書き込むことができます。

  • クラスに、指定された名前と関連付けられたセッターメソッドがある場合(この場合、プロパティ名はケースインセンシティブです)。
  • クラスに、指定された名前のメンバ変数がある場合($checkVars が true の場合)。
  • アタッチされたビヘイビアに、指定された名前の書き込み可能なプロパティがある場合($checkBehaviors が true の場合)。
public boolean canSetProperty ( $name, $checkVars true, $checkBehaviors true )
$name string

プロパティ名

$checkVars boolean

メンバ変数をプロパティとして扱うかどうか

$checkBehaviors boolean

ビヘイビアのプロパティをこのコンポーネントのプロパティとして扱うかどうか

戻り値 boolean

プロパティを書き込むことができるかどうか

                public function canSetProperty($name, $checkVars = true, $checkBehaviors = true)
{
    if ($name === $this->filterAttributeName) {
        return true;
    }
    return parent::canSetProperty($name, $checkVars, $checkBehaviors);
}

            
className() public static メソッド
2.0.14から非推奨。PHP >= 5.5では、代わりに::classを使用してください。

定義されている場所: yii\base\BaseObject::className()

このクラスの完全修飾名を返します。

public static string className ( )
戻り値 string

このクラスの完全修飾名。

                public static function className()
{
    return get_called_class();
}

            
clearErrors() public メソッド

定義されている場所: yii\base\Model::clearErrors()

すべての属性または単一の属性のエラーを削除します。

public void clearErrors ( $attribute null )
$attribute string|null

属性名。すべての属性のエラーを削除するには null を使用します。

                public function clearErrors($attribute = null)
{
    if ($attribute === null) {
        $this->_errors = [];
    } else {
        unset($this->_errors[$attribute]);
    }
}

            
createValidators() public メソッド

定義されている場所: yii\base\Model::createValidators()

rules()で指定された検証ルールに基づいて、バリデータオブジェクトを作成します。

getValidators()とは異なり、このメソッドが呼び出されるたびに、新しいバリデータのリストが返されます。

public ArrayObject createValidators ( )
戻り値 ArrayObject

バリデータ

例外 yii\base\InvalidConfigException

検証ルールの設定が無効な場合

                public function createValidators()
{
    $validators = new ArrayObject();
    foreach ($this->rules() as $rule) {
        if ($rule instanceof Validator) {
            $validators->append($rule);
        } elseif (is_array($rule) && isset($rule[0], $rule[1])) { // attributes, validator type
            $validator = Validator::createValidator($rule[1], $this, (array) $rule[0], array_slice($rule, 2));
            $validators->append($validator);
        } else {
            throw new InvalidConfigException('Invalid validation rule: a rule must specify both attribute names and validator type.');
        }
    }
    return $validators;
}

            
defaultErrorMessages() protected メソッド

定義されている場所: yii\data\DataFilter::defaultErrorMessages()

$errorMessagesのデフォルト値を返します。

protected array defaultErrorMessages ( )
戻り値 array

[errorKey => message]形式のデフォルトエラーメッセージ。

                protected function defaultErrorMessages()
{
    return [
        'invalidFilter' => Yii::t('yii', 'The format of {filter} is invalid.'),
        'operatorRequireMultipleOperands' => Yii::t('yii', 'Operator "{operator}" requires multiple operands.'),
        'unknownAttribute' => Yii::t('yii', 'Unknown filter attribute "{attribute}"'),
        'invalidAttributeValueFormat' => Yii::t('yii', 'Condition for "{attribute}" should be either a value or valid operator specification.'),
        'operatorRequireAttribute' => Yii::t('yii', 'Operator "{operator}" must be used with a search attribute.'),
        'unsupportedOperatorType' => Yii::t('yii', '"{attribute}" does not support operator "{operator}".'),
    ];
}

            
detachBehavior() publicメソッド

定義位置: yii\base\Component::detachBehavior()

コンポーネントからビヘイビアをデタッチします。

ビヘイビアのyii\base\Behavior::detach()メソッドが呼び出されます。

public yii\base\Behavior|null detachBehavior ( $name )
$name string

ビヘイビアの名前。

戻り値 yii\base\Behavior|null

デタッチされたビヘイビア。ビヘイビアが存在しない場合はNull。

                public function detachBehavior($name)
{
    $this->ensureBehaviors();
    if (isset($this->_behaviors[$name])) {
        $behavior = $this->_behaviors[$name];
        unset($this->_behaviors[$name]);
        $behavior->detach();
        return $behavior;
    }
    return null;
}

            
detachBehaviors() publicメソッド

定義位置: yii\base\Component::detachBehaviors()

コンポーネントからすべてのビヘイビアをデタッチします。

public void detachBehaviors ( )

                public function detachBehaviors()
{
    $this->ensureBehaviors();
    foreach ($this->_behaviors as $name => $behavior) {
        $this->detachBehavior($name);
    }
}

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

定義位置: yii\data\DataFilter::detectSearchAttributeType()

与えられたバリデータ(検証子)から属性タイプを検出します。

protected string|null detectSearchAttributeType ( yii\validators\Validator $validator )
$validator yii\validators\Validator

属性の種類を検出するバリデータ。

戻り値 string|null

検出された属性の種類。

                protected function detectSearchAttributeType(Validator $validator)
{
    if ($validator instanceof BooleanValidator) {
        return self::TYPE_BOOLEAN;
    }
    if ($validator instanceof NumberValidator) {
        return $validator->integerOnly ? self::TYPE_INTEGER : self::TYPE_FLOAT;
    }
    if ($validator instanceof StringValidator) {
        return self::TYPE_STRING;
    }
    if ($validator instanceof EachValidator) {
        return self::TYPE_ARRAY;
    }
    if ($validator instanceof DateValidator) {
        if ($validator->type == DateValidator::TYPE_DATETIME) {
            return self::TYPE_DATETIME;
        }
        if ($validator->type == DateValidator::TYPE_TIME) {
            return self::TYPE_TIME;
        }
        return self::TYPE_DATE;
    }
}

            
detectSearchAttributeTypes() protectedメソッド

定義位置: yii\data\DataFilter::detectSearchAttributeTypes()

$searchModelのバリデーションルール(検証ルール)から$searchAttributeTypesのデフォルト値を構成します。

protected array detectSearchAttributeTypes ( )
戻り値 array

属性の種類マップ。

                protected function detectSearchAttributeTypes()
{
    $model = $this->getSearchModel();
    $attributeTypes = [];
    foreach ($model->activeAttributes() as $attribute) {
        $attributeTypes[$attribute] = self::TYPE_STRING;
    }
    foreach ($model->getValidators() as $validator) {
        $type = $this->detectSearchAttributeType($validator);
        if ($type !== null) {
            foreach ((array) $validator->attributes as $attribute) {
                $attributeTypes[$attribute] = $type;
            }
        }
    }
    return $attributeTypes;
}

            
ensureBehaviors() publicメソッド

定義位置: yii\base\Component::ensureBehaviors()

behaviors()で宣言されたビヘイビアがこのコンポーネントにアタッチされていることを確認します。

public void ensureBehaviors ( )

                public function ensureBehaviors()
{
    if ($this->_behaviors === null) {
        $this->_behaviors = [];
        foreach ($this->behaviors() as $name => $behavior) {
            $this->attachBehaviorInternal($name, $behavior);
        }
    }
}

            
extraFields() publicメソッド

定義位置: yii\base\ArrayableTrait::extraFields()

toArray()によってさらに展開され、返されるフィールドのリストを返します。

このメソッドはfields()と似ていますが、このメソッドによって返されるフィールドのリストは、toArray()によってデフォルトでは返されません。toArray()を呼び出す際に展開するフィールド名を明示的に指定した場合のみ、それらの値がエクスポートされます。

デフォルトの実装では空の配列を返します。

コンテキスト情報(例:現在のアプリケーションユーザー)に基づいて、展開可能なフィールドのリストを返すようにこのメソッドをオーバーライドできます。

参照

public array extraFields ( )
戻り値 array

展開可能なフィールド名またはフィールド定義のリスト。fields()で戻り値の形式を参照してください。

                public function extraFields()
{
    return [];
}

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

定義位置: yii\base\ArrayableTrait::extractFieldsFor()

指定されたルートフィールドに対して、フィールドコレクションからネストされたフィールドを抽出します。ネストされたフィールドはドット(.)で区切られます。例:「item.id」この例では「id」が抽出されます。

protected array extractFieldsFor ( array $fields, $rootField )
$fields array

抽出を要求されたフィールド。

$rootField string

ネストされたフィールドを抽出したいルートフィールド。

戻り値 array

指定されたフィールドに対して抽出されたネストされたフィールド。

                protected function extractFieldsFor(array $fields, $rootField)
{
    $result = [];
    foreach ($fields as $field) {
        if (0 === strpos($field, "{$rootField}.")) {
            $result[] = preg_replace('/^' . preg_quote($rootField, '/') . '\./i', '', $field);
        }
    }
    return array_unique($result);
}

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

定義位置: yii\base\ArrayableTrait::extractRootFields()

ネストされたフィールドからルートフィールド名を抽出します。

ネストされたフィールドはドット(.)で区切られます。例:"item.id" 前の例では "item" が抽出されます。

protected array extractRootFields ( array $fields )
$fields array

抽出を要求されたフィールド。

戻り値 array

指定されたネストされたフィールドから抽出されたルートフィールド。

                protected function extractRootFields(array $fields)
{
    $result = [];
    foreach ($fields as $field) {
        $result[] = current(explode('.', $field, 2));
    }
    if (in_array('*', $result, true)) {
        $result = [];
    }
    return array_unique($result);
}

            
fields() publicメソッド

定義位置: yii\base\ArrayableTrait::fields()

特定のフィールドが指定されていない場合、toArray()によってデフォルトで返されるべきフィールドのリストを返します。

toArray()によって返される配列内の名前付き要素はフィールドです。

このメソッドは、フィールド名またはフィールド定義の配列を返す必要があります。前者の場合、フィールド名はオブジェクトのプロパティ名として扱われ、その値がフィールド値として使用されます。後者の場合、配列のキーはフィールド名で、配列の値は対応するフィールド定義になります。フィールド定義はオブジェクトのプロパティ名、または対応するフィールド値を返すPHPのcallableのいずれかです。callableのシグネチャは次のようになります。

function ($model, $field) {
    // return field value
}

たとえば、次のコードは4つのフィールドを宣言します。

  • email: フィールド名はプロパティ名emailと同じです。
  • firstNamelastName: フィールド名はfirstNamelastNameで、それらの値はfirst_namelast_nameのプロパティから取得されます。
  • fullName: フィールド名はfullNameです。その値はfirst_namelast_nameを連結して取得されます。
return [
    'email',
    'firstName' => 'first_name',
    'lastName' => 'last_name',
    'fullName' => function () {
        return $this->first_name . ' ' . $this->last_name;
    },
];

このメソッドでは、コンテキスト情報に基づいて異なるフィールドのリストを返すこともできます。たとえば、現在のアプリケーションユーザーの権限に応じて、表示可能なフィールドの異なるセットを返したり、一部のフィールドをフィルタリングしたりできます。

このメソッドのデフォルトの実装では、それ自身によってインデックス付けされた公開オブジェクトメンバ変数を返します。

参照 toArray().

public array fields ( )
戻り値 array

フィールド名またはフィールド定義のリスト。

                public function fields()
{
    $fields = array_keys(Yii::getObjectVars($this));
    return array_combine($fields, $fields);
}

            
filterAttributeValue() protectedメソッド

定義位置: yii\data\DataFilter::filterAttributeValue()

属性値フィルタがあれば適用して、$searchModelの範囲内で属性値を検証します。

protected 混合型 filterAttributeValue ( $attribute, $value )
$attribute string

属性名。

$value mixed

属性値。

戻り値 mixed

フィルタリングされた属性値。

                protected function filterAttributeValue($attribute, $value)
{
    $model = $this->getSearchModel();
    if (!$model->isAttributeSafe($attribute)) {
        $this->addError($this->filterAttributeName, $this->parseErrorMessage('unknownAttribute', ['attribute' => $attribute]));
        return $value;
    }
    $model->{$attribute} = $value;
    if (!$model->validate([$attribute])) {
        $this->addError($this->filterAttributeName, $model->getFirstError($attribute));
        return $value;
    }
    return $model->{$attribute};
}

            
formName() publicメソッド

定義位置: yii\data\DataFilter::formName()

このモデルクラスが使用するフォーム名を返します。

yii\widgets\ActiveForm は、主にフォーム名を使用して、モデル内の属性の入力フィールドの命名方法を決定します。フォーム名が "A" で属性名が "b" の場合、対応する入力名は "A[b]" になります。フォーム名が空文字列の場合、入力名は "b" になります。

上記の命名スキームの目的は、複数の異なるモデルを含むフォームの場合、各モデルの属性はPOSTデータのサブ配列にグループ化され、それらを区別しやすくなることです。

デフォルトでは、このメソッドはフォーム名としてモデルクラス名(名前空間部分は除く)を返します。モデルが異なるフォームで使用される場合は、これをオーバーライドできます。

public string formName ( )
戻り値 string

このモデルクラスのフォーム名。

例外 yii\base\InvalidConfigException

フォームが匿名クラスで定義され、formName()メソッドがオーバーライドされていない場合。

                public function formName()
{
    return '';
}

            
generateAttributeLabel() publicメソッド

定義位置: yii\base\Model::generateAttributeLabel()

与えられた属性名に基づいて、ユーザーフレンドリーな属性ラベルを生成します。

これは、アンダースコア、ダッシュ、ドットを空白に置き換え、各単語の最初の文字を大文字にすることによって行われます。たとえば、「department_name」または「DepartmentName」は「Department Name」を生成します。

public string generateAttributeLabel ( $name )
$name string

カラム名

戻り値 string

属性ラベル

                public function generateAttributeLabel($name)
{
    return Inflector::camel2words($name, true);
}

            
getActiveValidators() publicメソッド

定義位置: yii\base\Model::getActiveValidators()

現在の$scenarioに適用可能なバリデータ(検証子)を返します。

public yii\validators\Validator[] getActiveValidators ( $attribute null )
$attribute string|null

適用可能なバリデータが返される属性の名前。これがnullの場合、モデル内のすべての属性のバリデータが返されます。

戻り値 yii\validators\Validator[]

現在の$scenarioに適用可能なバリデータ。

                public function getActiveValidators($attribute = null)
{
    $activeAttributes = $this->activeAttributes();
    if ($attribute !== null && !in_array($attribute, $activeAttributes, true)) {
        return [];
    }
    $scenario = $this->getScenario();
    $validators = [];
    foreach ($this->getValidators() as $validator) {
        if ($attribute === null) {
            $validatorAttributes = $validator->getValidationAttributes($activeAttributes);
            $attributeValid = !empty($validatorAttributes);
        } else {
            $attributeValid = in_array($attribute, $validator->getValidationAttributes($attribute), true);
        }
        if ($attributeValid && $validator->isActive($scenario)) {
            $validators[] = $validator;
        }
    }
    return $validators;
}

            
getAttributeHint() publicメソッド (バージョン2.0.4以降で利用可能)

定義位置: yii\base\Model::getAttributeHint()

指定された属性のテキストヒントを返します。

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

public string getAttributeHint ( $attribute )
$attribute string

属性名

戻り値 string

属性ヒント

                public function getAttributeHint($attribute)
{
    $hints = $this->attributeHints();
    return isset($hints[$attribute]) ? $hints[$attribute] : '';
}

            
getAttributeLabel() publicメソッド

定義位置: yii\base\Model::getAttributeLabel()

指定された属性のテキストラベルを返します。

参照

public string getAttributeLabel ( $attribute )
$attribute string

属性名

戻り値 string

属性ラベル

                public function getAttributeLabel($attribute)
{
    $labels = $this->attributeLabels();
    return isset($labels[$attribute]) ? $labels[$attribute] : $this->generateAttributeLabel($attribute);
}

            
getAttributes() publicメソッド

定義位置: yii\base\Model::getAttributes()

属性値を返します。

public array getAttributes ( $names null, $except = [] )
$names array|null

値を返す必要がある属性のリスト。デフォルトはnullで、attributes()にリストされているすべての属性が返されます。配列の場合、配列内の属性のみが返されます。

$except array

値を返すべきではない属性のリスト。

戻り値 array

属性値 (名前 => 値)。

                public function getAttributes($names = null, $except = [])
{
    $values = [];
    if ($names === null) {
        $names = $this->attributes();
    }
    foreach ($names as $name) {
        $values[$name] = $this->$name;
    }
    foreach ($except as $name) {
        unset($values[$name]);
    }
    return $values;
}

            
getBehavior() publicメソッド

定義位置: yii\base\Component::getBehavior()

名前付きのビヘイビアオブジェクトを返します。

public yii\base\Behavior|null getBehavior ( $name )
$name string

ビヘイビア名

戻り値 yii\base\Behavior|null

ビヘイビアオブジェクト、またはビヘイビアが存在しない場合はnull

                public function getBehavior($name)
{
    $this->ensureBehaviors();
    return isset($this->_behaviors[$name]) ? $this->_behaviors[$name] : null;
}

            
getBehaviors() publicメソッド

定義位置: yii\base\Component::getBehaviors()

このコンポーネントにアタッチされているすべてのビヘイビアを返します。

public yii\base\Behavior[] getBehaviors ( )
戻り値 yii\base\Behavior[]

このコンポーネントにアタッチされているビヘイビアのリスト

                public function getBehaviors()
{
    $this->ensureBehaviors();
    return $this->_behaviors;
}

            
getErrorMessages() publicメソッド
public array getErrorMessages ( )
戻り値 array

[errorKey => message]形式のエラーメッセージ。

                public function getErrorMessages()
{
    if (!is_array($this->_errorMessages)) {
        if ($this->_errorMessages === null) {
            $this->_errorMessages = $this->defaultErrorMessages();
        } else {
            $this->_errorMessages = array_merge(
                $this->defaultErrorMessages(),
                call_user_func($this->_errorMessages)
            );
        }
    }
    return $this->_errorMessages;
}

            
getErrorSummary() publicメソッド (バージョン2.0.14以降で利用可能)

定義位置: yii\base\Model::getErrorSummary()

すべての属性のエラーを一次元配列として返します。

参照

public array getErrorSummary ( $showAllErrors )
$showAllErrors boolean

ブール値。trueに設定すると、各属性のすべてのエラーメッセージが表示され、それ以外の場合は各属性の最初のエラーメッセージのみが表示されます。

戻り値 array

すべての属性のエラーを一次元配列として表示します。エラーがない場合は空の配列が返されます。

                public function getErrorSummary($showAllErrors)
{
    $lines = [];
    $errors = $showAllErrors ? $this->getErrors() : $this->getFirstErrors();
    foreach ($errors as $es) {
        $lines = array_merge($lines, (array)$es);
    }
    return $lines;
}

            
getErrors() publicメソッド

定義位置: yii\base\Model::getErrors()

すべての属性または単一の属性のエラーを返します。

参照

public array getErrors ( $attribute null )
$attribute string|null

属性名。すべての属性のエラーを取得するにはnullを使用します。

戻り値 array

すべての属性、または指定された属性のエラー。エラーがない場合は空の配列が返されます。getErrors()で詳細な説明を参照してください。すべての属性のエラーを返す場合、結果は次のような二次元配列になります。

[
    'username' => [
        'Username is required.',
        'Username must contain only word characters.',
    ],
    'email' => [
        'Email address is invalid.',
    ]
]

                public function getErrors($attribute = null)
{
    if ($attribute === null) {
        return $this->_errors === null ? [] : $this->_errors;
    }
    return isset($this->_errors[$attribute]) ? $this->_errors[$attribute] : [];
}

            
getFilter() publicメソッド
public mixed getFilter ( )
戻り値 mixed

生のフィルタ値。

                public function getFilter()
{
    return $this->_filter;
}

            
getFirstError() publicメソッド

定義位置: yii\base\Model::getFirstError()

指定された属性の最初のエラーを返します。

参照

public string|null getFirstError ( $attribute )
$attribute string

属性名。

戻り値 string|null

エラーメッセージ。エラーがない場合はNullを返します。

                public function getFirstError($attribute)
{
    return isset($this->_errors[$attribute]) ? reset($this->_errors[$attribute]) : null;
}

            
getFirstErrors() publicメソッド

定義位置: yii\base\Model::getFirstErrors()

モデル内の各属性の最初のエラーを返します。

参照

public array getFirstErrors ( )
戻り値 array

最初のエラー。配列のキーは属性名、値は対応するエラーメッセージです。エラーがない場合は空の配列を返します。

                public function getFirstErrors()
{
    if (empty($this->_errors)) {
        return [];
    }
    $errors = [];
    foreach ($this->_errors as $name => $es) {
        if (!empty($es)) {
            $errors[$name] = reset($es);
        }
    }
    return $errors;
}

            
getIterator() publicメソッド

定義位置: yii\base\Model::getIterator()

モデル内の属性をトラバースするためのイテレータを返します。

このメソッドは、IteratorAggregate インターフェースで必須です。

public ArrayIterator getIterator ( )
戻り値 ArrayIterator

リスト内のアイテムをトラバースするためのイテレータ。

                #[\ReturnTypeWillChange]
public function getIterator()
{
    $attributes = $this->getAttributes();
    return new ArrayIterator($attributes);
}

            
getScenario() publicメソッド

定義位置: yii\base\Model::getScenario()

このモデルが使用されているシナリオを返します。

シナリオは、バリデーションの実行方法と、大量代入可能な属性に影響します。

public string getScenario ( )
戻り値 string

このモデルが存在するシナリオ。デフォルトはSCENARIO_DEFAULTです。

                public function getScenario()
{
    return $this->_scenario;
}

            
getSearchAttributeTypes() publicメソッド
public array getSearchAttributeTypes ( )
戻り値 array

検索属性タイプのマップ。

                public function getSearchAttributeTypes()
{
    if ($this->_searchAttributeTypes === null) {
        $this->_searchAttributeTypes = $this->detectSearchAttributeTypes();
    }
    return $this->_searchAttributeTypes;
}

            
getSearchModel() publicメソッド
public yii\base\Model getSearchModel ( )
戻り値 yii\base\Model

モデルインスタンス。

例外 yii\base\InvalidConfigException

無効な設定の場合。

                public function getSearchModel()
{
    if (!is_object($this->_searchModel) || $this->_searchModel instanceof \Closure) {
        $model = Yii::createObject($this->_searchModel);
        if (!$model instanceof Model) {
            throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::className() . '` or its DI compatible configuration.');
        }
        $this->_searchModel = $model;
    }
    return $this->_searchModel;
}

            
getValidators() publicメソッド

定義位置: yii\base\Model::getValidators()

rules()で宣言されているすべてのバリデータ(検証子)を返します。

このメソッドは、後者が現在の$scenarioに適用可能なバリデーターのみを返すという点で、getActiveValidators()とは異なります。

このメソッドはArrayObjectオブジェクトを返すため、バリデーターの挿入や削除を行うことができます(モデルビヘイビアで役立ちます)。例えば、

$model->validators[] = $newValidator;
public ArrayObject|yii\validators\Validator[] getValidators ( )
戻り値 ArrayObject|yii\validators\Validator[]

モデルで宣言されているすべてのバリデータ。

                public function getValidators()
{
    if ($this->_validators === null) {
        $this->_validators = $this->createValidators();
    }
    return $this->_validators;
}

            
hasErrors() publicメソッド

定義位置: yii\base\Model::hasErrors()

バリデーションエラーがあるかどうかを示す値を返します。

public boolean hasErrors ( $attribute null )
$attribute string|null

属性名。すべての属性をチェックするにはnullを使用します。

戻り値 boolean

エラーがあるかどうか。

                public function hasErrors($attribute = null)
{
    return $attribute === null ? !empty($this->_errors) : isset($this->_errors[$attribute]);
}

            
hasEventHandlers() publicメソッド

定義位置: yii\base\Component::hasEventHandlers()

名前付きイベントにハンドラーがアタッチされているかどうかを示す値を返します。

public boolean hasEventHandlers ( $name )
$name string

イベント名

戻り値 boolean

イベントにハンドラーがアタッチされているかどうか。

                public function hasEventHandlers($name)
{
    $this->ensureBehaviors();
    if (!empty($this->_events[$name])) {
        return true;
    }
    foreach ($this->_eventWildcards as $wildcard => $handlers) {
        if (!empty($handlers) && StringHelper::matchWildcard($wildcard, $name)) {
            return true;
        }
    }
    return Event::hasHandlers($this, $name);
}

            
hasMethod() publicメソッド

定義位置: yii\base\Component::hasMethod()

メソッドが定義されているかどうかを示す値を返します。

メソッドは、以下の場合に定義されています。

  • クラスが指定された名前のメソッドを持っている場合
  • アタッチされたビヘイビアが指定された名前のメソッドを持っている場合($checkBehaviorsがtrueの場合)。
public boolean hasMethod ( $name, $checkBehaviors true )
$name string

プロパティ名

$checkBehaviors boolean

ビヘイビアのメソッドをこのコンポーネントのメソッドとして扱うかどうか

戻り値 boolean

メソッドが定義されているかどうか

                public function hasMethod($name, $checkBehaviors = true)
{
    if (method_exists($this, $name)) {
        return true;
    } elseif ($checkBehaviors) {
        $this->ensureBehaviors();
        foreach ($this->_behaviors as $behavior) {
            if ($behavior->hasMethod($name)) {
                return true;
            }
        }
    }
    return false;
}

            
hasProperty() publicメソッド

定義位置: yii\base\Component::hasProperty()

このコンポーネントにプロパティが定義されているかどうかを示す値を返します。

プロパティは、以下の場合に定義されています。

  • クラスが指定された名前と関連付けられたゲッターまたはセッターメソッドを持っている場合(この場合、プロパティ名はケースインセンシティブです)。
  • クラスに、指定された名前のメンバ変数がある場合($checkVars が true の場合)。
  • アタッチされたビヘイビアが指定された名前のプロパティを持っている場合($checkBehaviorsがtrueの場合)。

参照

public boolean hasProperty ( $name, $checkVars true, $checkBehaviors true )
$name string

プロパティ名

$checkVars boolean

メンバ変数をプロパティとして扱うかどうか

$checkBehaviors boolean

ビヘイビアのプロパティをこのコンポーネントのプロパティとして扱うかどうか

戻り値 boolean

プロパティが定義されているかどうか

                public function hasProperty($name, $checkVars = true, $checkBehaviors = true)
{
    return $this->canGetProperty($name, $checkVars, $checkBehaviors) || $this->canSetProperty($name, false, $checkBehaviors);
}

            
init() publicメソッド

定義位置: yii\base\BaseObject::init()

オブジェクトを初期化します。

このメソッドは、オブジェクトが指定された設定で初期化された後、コンストラクタの最後に呼び出されます。

public void init ( )

                public function init()
{
}

            
instance() public staticメソッド

定義位置: yii\base\StaticInstanceTrait::instance()

メタ情報を取得するために使用できる、静的クラスインスタンスを返します。

public static static instance ( $refresh false )
$refresh boolean

既にキャッシュされている場合でも、静的インスタンスを再作成するかどうか。

戻り値 yii\data\ActiveDataFilter

クラスインスタンス。

                public static function instance($refresh = false)
{
    $className = get_called_class();
    if ($refresh || !isset(self::$_instances[$className])) {
        self::$_instances[$className] = Yii::createObject($className);
    }
    return self::$_instances[$className];
}

            
isAttributeActive() publicメソッド

定義位置: yii\base\Model::isAttributeActive()

現在のシナリオで属性がアクティブかどうかを示す値を返します。

参照: activeAttributes().

public boolean isAttributeActive ( $attribute )
$attribute string

属性名

戻り値 boolean

属性が現在のシナリオで有効かどうか。

                public function isAttributeActive($attribute)
{
    return in_array($attribute, $this->activeAttributes(), true);
}

            
isAttributeRequired() publicメソッド

定義位置: yii\base\Model::isAttributeRequired()

属性が必須かどうかを示す値を返します。

これは、属性が現在の$scenariorequiredバリデーションルールに関連付けられているかどうかをチェックすることで決定されます。

$whenを使用して条件付きバリデーションが適用されている場合、このメソッドはモデルがデータでロードされる前に呼び出される可能性があるため、when条件に関係なくfalseを返します。

public boolean isAttributeRequired ( $attribute )
$attribute string

属性名

戻り値 boolean

属性が必要かどうか。

                public function isAttributeRequired($attribute)
{
    foreach ($this->getActiveValidators($attribute) as $validator) {
        if ($validator instanceof RequiredValidator && $validator->when === null) {
            return true;
        }
    }
    return false;
}

            
isAttributeSafe() publicメソッド

定義位置: yii\base\Model::isAttributeSafe()

属性が大量代入に対して安全かどうかを示す値を返します。

参照: safeAttributes().

public boolean isAttributeSafe ( $attribute )
$attribute string

属性名

戻り値 boolean

属性が大量代入に対して安全かどうか。

                public function isAttributeSafe($attribute)
{
    return in_array($attribute, $this->safeAttributes(), true);
}

            
load() publicメソッド

定義位置: yii\base\Model::load()

入力データでモデルを設定します。

このメソッドは、以下の簡略化されたショートカットを提供します。

if (isset($_POST['FormName'])) {
    $model->attributes = $_POST['FormName'];
    if ($model->save()) {
        // handle success
    }
}

これは、load()を使うと次のように記述できます。

if ($model->load($_POST) && $model->save()) {
    // handle success
}

load()は、$formNameパラメータが指定されていない限り、モデルのformName()メソッド(オーバーライドできます)から'FormName'を取得します。フォーム名が空の場合、load()$data['FormName']ではなく、$data全体でモデルを移入します。

移入されるデータは、setAttributes()による安全性のチェックの対象となります。

public boolean load ( $data, $formName null )
$data array

ロードするデータの配列。通常は$_POSTまたは$_GET

$formName string|null

モデルにデータを読み込むために使用するフォーム名。フォームを使用しない場合は空文字列。設定されていない場合、formName()が使用されます。

戻り値 boolean

load()$data内で期待されるフォームを見つけたかどうか。

                public function load($data, $formName = null)
{
    $scope = $formName === null ? $this->formName() : $formName;
    if ($scope === '' && !empty($data)) {
        $this->setAttributes($data);
        return true;
    } elseif (isset($data[$scope])) {
        $this->setAttributes($data[$scope]);
        return true;
    }
    return false;
}

            
loadMultiple() public staticメソッド

定義位置: yii\base\Model::loadMultiple()

エンドユーザーからのデータを使用して、一連のモデルを設定します。

このメソッドは主に、表形式のデータ入力の収集に使用されます。各モデルに対してロードされるデータは$data[formName][index]です。ここで、formNameformName()の値、index$models配列内のモデルのインデックスです。formName()が空の場合、$data[index]を使用して各モデルに移入されます。各モデルに移入されるデータは、setAttributes()による安全性のチェックの対象となります。

public static boolean loadMultiple ( $models, $data, $formName null )
$models array

移入されるモデル。すべてのモデルは同じクラスである必要があります。

$data array

データの配列。通常は$_POSTまたは$_GETですが、エンドユーザーが提供する有効な配列であれば何でもかまいません。

$formName string|null

モデルにデータを読み込むために使用するフォーム名。設定されていない場合、$modelsの最初のモデルのformName()値が使用されます。このパラメータはバージョン2.0.1から利用可能です。

戻り値 boolean

少なくとも1つのモデルが正常に移入されたかどうか。

                public static function loadMultiple($models, $data, $formName = null)
{
    if ($formName === null) {
        /* @var $first Model|false */
        $first = reset($models);
        if ($first === false) {
            return false;
        }
        $formName = $first->formName();
    }
    $success = false;
    foreach ($models as $i => $model) {
        /* @var $model Model */
        if ($formName == '') {
            if (!empty($data[$i]) && $model->load($data[$i], '')) {
                $success = true;
            }
        } elseif (!empty($data[$formName][$i]) && $model->load($data[$formName][$i], '')) {
            $success = true;
        }
    }
    return $success;
}

            
normalize() publicメソッド

定義位置: yii\data\DataFilter::normalize()

$filterControls$attributeMapに従って、生のキーを置き換えることで、フィルタ値を正規化します。

public array|boolean normalize ( $runValidation true )
$runValidation boolean

フィルターを正規化する前にバリデーションを実行するかどうか(validate()を呼び出す)。デフォルトはtrueです。バリデーションに失敗した場合、フィルターは処理されず、このメソッドはfalseを返します。

戻り値 array|boolean

正規化されたフィルター値、またはバリデーションに失敗した場合はfalse

                public function normalize($runValidation = true)
{
    if ($runValidation && !$this->validate()) {
        return false;
    }
    $filter = $this->getFilter();
    if (!is_array($filter) || empty($filter)) {
        return [];
    }
    return $this->normalizeComplexFilter($filter);
}

            
off() publicメソッド

定義位置: yii\base\Component::off()

このコンポーネントから既存のイベントハンドラーをデタッチします。

このメソッドはon()の反対です。

注:イベント名にワイルドカードパターンが渡された場合、このワイルドカードで登録されたハンドラーのみが削除され、このワイルドカードと一致するプレーン名で登録されたハンドラーは残ります。

参照: on().

public boolean off ( $name, $handler null )
$name string

イベント名

$handler callable|null

削除するイベントハンドラー。nullの場合、指定されたイベントにアタッチされたすべてのハンドラーが削除されます。

戻り値 boolean

ハンドラーが見つかり、デタッチされた場合。

                public function off($name, $handler = null)
{
    $this->ensureBehaviors();
    if (empty($this->_events[$name]) && empty($this->_eventWildcards[$name])) {
        return false;
    }
    if ($handler === null) {
        unset($this->_events[$name], $this->_eventWildcards[$name]);
        return true;
    }
    $removed = false;
    // plain event names
    if (isset($this->_events[$name])) {
        foreach ($this->_events[$name] as $i => $event) {
            if ($event[0] === $handler) {
                unset($this->_events[$name][$i]);
                $removed = true;
            }
        }
        if ($removed) {
            $this->_events[$name] = array_values($this->_events[$name]);
            return true;
        }
    }
    // wildcard event names
    if (isset($this->_eventWildcards[$name])) {
        foreach ($this->_eventWildcards[$name] as $i => $event) {
            if ($event[0] === $handler) {
                unset($this->_eventWildcards[$name][$i]);
                $removed = true;
            }
        }
        if ($removed) {
            $this->_eventWildcards[$name] = array_values($this->_eventWildcards[$name]);
            // remove empty wildcards to save future redundant regex checks:
            if (empty($this->_eventWildcards[$name])) {
                unset($this->_eventWildcards[$name]);
            }
        }
    }
    return $removed;
}

            
offsetExists() publicメソッド

定義位置: yii\base\Model::offsetExists()

指定されたオフセットに要素があるかどうかを返します。

このメソッドは、SPLインターフェースArrayAccessで必要です。isset($model[$offset])のようなものを使用すると、暗黙的に呼び出されます。

public boolean offsetExists ( $offset )
$offset string

確認するオフセット。

戻り値 boolean

オフセットが存在するかどうか。

                #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
    return isset($this->$offset);
}

            
offsetGet() publicメソッド

定義位置: yii\base\Model::offsetGet()

指定されたオフセットの要素を返します。

このメソッドはSPLインターフェースArrayAccessで必須です。`$value = $model[$offset];`のような記述で使用されると暗黙的に呼び出されます。

public mixed offsetGet ( $offset )
$offset string

要素を取得するオフセット。

戻り値 mixed

オフセットにある要素。オフセットに要素がない場合はnull。

                #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
    return $this->$offset;
}

            
offsetSet() publicメソッド

定義位置: yii\base\Model::offsetSet()

指定されたオフセットに要素を設定します。

このメソッドはSPLインターフェースArrayAccessで必須です。`$model[$offset] = $value;`のような記述で使用されると暗黙的に呼び出されます。

public void offsetSet ( $offset, $value )
$offset string

要素を設定するオフセット。

$value mixed

要素の値。

                #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
    $this->$offset = $value;
}

            
offsetUnset() publicメソッド

定義位置: yii\base\Model::offsetUnset()

指定されたオフセットの要素値をnullに設定します。

このメソッドはSPLインターフェースArrayAccessで必須です。`unset($model[$offset])`のような記述で使用されると暗黙的に呼び出されます。

public void offsetUnset ( $offset )
$offset string

要素をアンセットするオフセット。

                #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
    $this->$offset = null;
}

            
on() publicメソッド

定義位置: yii\base\Component::on()

イベントにイベントハンドラーをアタッチします。

イベントハンドラは有効なPHPコールバックでなければなりません。いくつかの例を以下に示します。

function ($event) { ... }         // anonymous function
[$object, 'handleClick']          // $object->handleClick()
['Page', 'handleClick']           // Page::handleClick()
'handleClick'                     // global function handleClick()

イベントハンドラは、以下のシグネチャで定義する必要があります。

function ($event)

ここで、`$event`はイベントに関連付けられたパラメータを含むyii\base\Eventオブジェクトです。

2.0.14以降、イベント名をワイルドカードパターンとして指定できます。

$component->on('event.group.*', function ($event) {
    Yii::trace($event->name . ' is triggered.');
});

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

public void on ( $name, $handler, $data null, $append true )
$name string

イベント名

$handler callable

イベントハンドラ。

$data mixed

イベントが発生したときにイベントハンドラに渡されるデータ。イベントハンドラが呼び出されると、このデータはyii\base\Event::$dataからアクセスできます。

$append boolean

既存のハンドラリストの最後に新しいイベントハンドラを追加するかどうか。falseの場合、新しいハンドラは既存のハンドラリストの先頭に挿入されます。

                public function on($name, $handler, $data = null, $append = true)
{
    $this->ensureBehaviors();
    if (strpos($name, '*') !== false) {
        if ($append || empty($this->_eventWildcards[$name])) {
            $this->_eventWildcards[$name][] = [$handler, $data];
        } else {
            array_unshift($this->_eventWildcards[$name], [$handler, $data]);
        }
        return;
    }
    if ($append || empty($this->_events[$name])) {
        $this->_events[$name][] = [$handler, $data];
    } else {
        array_unshift($this->_events[$name], [$handler, $data]);
    }
}

            
onUnsafeAttribute() publicメソッド

定義位置: yii\base\Model::onUnsafeAttribute()

安全でない属性が大量に代入されている場合に呼び出されるメソッドです。

デフォルトの実装では、YII_DEBUGが有効な場合に警告メッセージをログに記録します。それ以外の場合は何も行いません。

public void onUnsafeAttribute ( $name, $value )
$name string

安全でない属性名。

$value mixed

属性値。

                public function onUnsafeAttribute($name, $value)
{
    if (YII_DEBUG) {
        Yii::debug("Failed to set unsafe attribute '$name' in '" . get_class($this) . "'.", __METHOD__);
    }
}

            
parseErrorMessage() protectedメソッド

定義位置: yii\data\DataFilter::parseErrorMessage()

メッセージキーで指定された$errorMessagesからのメッセージの内容を解析します。

protected string parseErrorMessage ( $messageKey, $params = [] )
$messageKey string

メッセージキー。

$params array

メッセージに解析されるパラメータ。

戻り値 string

合成されたメッセージ文字列。

                protected function parseErrorMessage($messageKey, $params = [])
{
    $messages = $this->getErrorMessages();
    if (isset($messages[$messageKey])) {
        $message = $messages[$messageKey];
    } else {
        $message = Yii::t('yii', 'The format of {filter} is invalid.');
    }
    $params = array_merge(
        [
            'filter' => $this->getAttributeLabel($this->filterAttributeName),
        ],
        $params
    );
    return Yii::$app->getI18n()->format($message, $params, Yii::$app->language);
}

            
resolveFields() protectedメソッド

定義位置: yii\base\ArrayableTrait::resolveFields()

toArray()によって返されるフィールドを決定します。

このメソッドはまず、指定されたフィールドからルートフィールドを抽出します。次に、fields()extraFields()で宣言されたフィールドに対して要求されたルートフィールドをチェックし、どのフィールドを返すことができるかを決定します。

protected array resolveFields ( array $fields, array $expand )
$fields array

エクスポートのために要求されているフィールド。

$expand array

エクスポートのために要求されている追加のフィールド。

戻り値 array

エクスポートされるフィールドのリスト。配列のキーはフィールド名で、配列の値は対応するオブジェクトのプロパティ名、またはフィールド値を返すPHPのcallableです。

                protected function resolveFields(array $fields, array $expand)
{
    $fields = $this->extractRootFields($fields);
    $expand = $this->extractRootFields($expand);
    $result = [];
    foreach ($this->fields() as $field => $definition) {
        if (is_int($field)) {
            $field = $definition;
        }
        if (empty($fields) || in_array($field, $fields, true)) {
            $result[$field] = $definition;
        }
    }
    if (empty($expand)) {
        return $result;
    }
    foreach ($this->extraFields() as $field => $definition) {
        if (is_int($field)) {
            $field = $definition;
        }
        if (in_array($field, $expand, true)) {
            $result[$field] = $definition;
        }
    }
    return $result;
}

            
rules() publicメソッド

定義位置: yii\data\DataFilter::rules()

属性のバリデーションルール(検証ルール)を返します。

バリデーションルールは、validate()によって属性値が有効かどうかをチェックするために使用されます。子クラスは、このメソッドをオーバーライドして異なるバリデーションルールを宣言できます。

各ルールは、以下の構造を持つ配列です。

[
    ['attribute1', 'attribute2'],
    'validator type',
    'on' => ['scenario1', 'scenario2'],
    //...other parameters...
]

ここで

  • 属性リスト: 必須。バリデートされる属性の配列を指定します。単一属性の場合は文字列を渡すことができます。
  • バリデータタイプ: 必須。使用するバリデータ名を指定します。ビルトインバリデータ名、モデルクラスのメソッド名、匿名関数、またはバリデータクラス名にすることができます。
  • on: オプション。バリデーションルールを適用できるシナリオの配列を指定します。このオプションが設定されていない場合、ルールはすべてのシナリオに適用されます。
  • 対応するバリデータのプロパティを初期化するために、追加の名前と値のペアを指定できます。可能なプロパティについては、個々のバリデータクラスのAPIを参照してください。

バリデータは、yii\validators\Validatorを拡張するクラスのオブジェクト、または以下のシグネチャを持つモデルクラスのメソッド(インラインバリデータと呼ばれます)のいずれかです。

// $params refers to validation parameters given in the rule
function validatorName($attribute, $params)

上記の`$attribute`は現在検証されている属性を参照し、`$params`は`max`(`string`バリデータの場合など)のようなバリデータ設定オプションの配列を含みます。現在検証されている属性の値は`$this->$attribute`としてアクセスできます。`attribute`の前に`$`があることに注意してください。これは変数`$attribute`の値を取り、それをプロパティ名として使用してアクセスしています。

Yiiは、ビルトインバリデータのセットも提供しています。それぞれにエイリアス名があり、バリデーションルールを指定する際に使用できます。

いくつかの例を以下に示します。

[
    // built-in "required" validator
    [['username', 'password'], 'required'],
    // built-in "string" validator customized with "min" and "max" properties
    ['username', 'string', 'min' => 3, 'max' => 12],
    // built-in "compare" validator that is used in "register" scenario only
    ['password', 'compare', 'compareAttribute' => 'password2', 'on' => 'register'],
    // an inline validator defined via the "authenticate()" method in the model class
    ['password', 'authenticate', 'on' => 'login'],
    // a validator of class "DateRangeValidator"
    ['dateRange', 'DateRangeValidator'],
];

親クラスで定義されたルールを継承するには、子クラスは`array_merge()`などの関数を使用して親ルールと子ルールをマージする必要があります。

public array rules ( )
戻り値 array

バリデーションルール。

                public function rules()
{
    return [
        [$this->filterAttributeName, 'validateFilter', 'skipOnEmpty' => false],
    ];
}

            
safeAttributes() publicメソッド

定義位置: yii\base\Model::safeAttributes()

現在のシナリオで大量に代入しても安全な属性名を返します。

public string[] safeAttributes ( )
戻り値 string[]

安全な属性名

                public function safeAttributes()
{
    $scenario = $this->getScenario();
    $scenarios = $this->scenarios();
    if (!isset($scenarios[$scenario])) {
        return [];
    }
    $attributes = [];
    foreach ($scenarios[$scenario] as $attribute) {
        if (
            $attribute !== ''
            && strncmp($attribute, '!', 1) !== 0
            && !in_array('!' . $attribute, $scenarios[$scenario])
        ) {
            $attributes[] = $attribute;
        }
    }
    return $attributes;
}

            
scenarios() publicメソッド

定義位置: yii\base\Model::scenarios()

シナリオと対応するアクティブな属性のリストを返します。

アクティブ属性とは、現在のシナリオでバリデーションの対象となる属性です。返される配列は、以下の形式である必要があります。

[
    'scenario1' => ['attribute11', 'attribute12', ...],
    'scenario2' => ['attribute21', 'attribute22', ...],
    ...
]

デフォルトでは、active属性は安全と見なされ、一括代入が可能です。属性を一括代入すべきでない場合(安全ではないと見なされる場合)、属性の前に感嘆符を付けます(例:'!rank')。

このメソッドのデフォルトの実装は、rules()宣言で見つかったすべてのシナリオを返します。SCENARIO_DEFAULTという特別なシナリオには、rules()にあるすべての属性が含まれます。各シナリオは、そのシナリオに適用される検証ルールによって検証される属性に関連付けられます。

public array scenarios ( )
戻り値 array

シナリオとその対応するactive属性のリスト。

                public function scenarios()
{
    $scenarios = [self::SCENARIO_DEFAULT => []];
    foreach ($this->getValidators() as $validator) {
        foreach ($validator->on as $scenario) {
            $scenarios[$scenario] = [];
        }
        foreach ($validator->except as $scenario) {
            $scenarios[$scenario] = [];
        }
    }
    $names = array_keys($scenarios);
    foreach ($this->getValidators() as $validator) {
        if (empty($validator->on) && empty($validator->except)) {
            foreach ($names as $name) {
                foreach ($validator->attributes as $attribute) {
                    $scenarios[$name][$attribute] = true;
                }
            }
        } elseif (empty($validator->on)) {
            foreach ($names as $name) {
                if (!in_array($name, $validator->except, true)) {
                    foreach ($validator->attributes as $attribute) {
                        $scenarios[$name][$attribute] = true;
                    }
                }
            }
        } else {
            foreach ($validator->on as $name) {
                foreach ($validator->attributes as $attribute) {
                    $scenarios[$name][$attribute] = true;
                }
            }
        }
    }
    foreach ($scenarios as $scenario => $attributes) {
        if (!empty($attributes)) {
            $scenarios[$scenario] = array_keys($attributes);
        }
    }
    return $scenarios;
}

            
setAttributes() publicメソッド

定義されている場所: yii\base\Model::setAttributes()

大量に属性値を設定します。

参照

public void setAttributes ( $values, $safeOnly true )
$values array

モデルに割り当てる属性値(名前 => 値)。

$safeOnly boolean

安全な属性のみに割り当てを行うかどうか。安全な属性とは、現在の$scenarioの検証ルールに関連付けられている属性です。

                public function setAttributes($values, $safeOnly = true)
{
    if (is_array($values)) {
        $attributes = array_flip($safeOnly ? $this->safeAttributes() : $this->attributes());
        foreach ($values as $name => $value) {
            if (isset($attributes[$name])) {
                $this->$name = $value;
            } elseif ($safeOnly) {
                $this->onUnsafeAttribute($name, $value);
            }
        }
    }
}

            
setErrorMessages() publicメソッド

定義されている場所: yii\data\DataFilter::setErrorMessages()

無効なフィルタ構造に対応するエラーメッセージのリストを`[errorKey => message]`の形式で設定します。

メッセージには、メッセージのコンテキストに応じて設定されるプレースホルダーを含めることができます。各メッセージには、$filterAttributeName属性のラベルを参照する{filter}プレースホルダーが使用できます。

public void setErrorMessages ( $errorMessages )
$errorMessages array|Closure

[errorKey => message]形式のエラーメッセージ、またはそれらを返すPHPコールバック。

                public function setErrorMessages($errorMessages)
{
    if (is_array($errorMessages)) {
        $errorMessages = array_merge($this->defaultErrorMessages(), $errorMessages);
    }
    $this->_errorMessages = $errorMessages;
}

            
setFilter() publicメソッド

定義されている場所: yii\data\DataFilter::setFilter()

public void setFilter ( $filter )
$filter mixed

生のフィルタ値。

                public function setFilter($filter)
{
    $this->_filter = $filter;
}

            
setScenario() publicメソッド

定義されている場所: yii\base\Model::setScenario()

モデルのシナリオを設定します。

このメソッドは、シナリオが存在するかどうかをチェックしません。validate()メソッドがこのチェックを実行します。

public void setScenario ( $value )
$value string

このモデルが存在するシナリオ。

                public function setScenario($value)
{
    $this->_scenario = $value;
}

            
setSearchAttributeTypes() publicメソッド

定義されている場所: yii\data\DataFilter::setSearchAttributeTypes()

public void setSearchAttributeTypes ( $searchAttributeTypes )
$searchAttributeTypes array|null

検索属性タイプのマップ。

                public function setSearchAttributeTypes($searchAttributeTypes)
{
    $this->_searchAttributeTypes = $searchAttributeTypes;
}

            
setSearchModel() publicメソッド

定義されている場所: yii\data\DataFilter::setSearchModel()

public void setSearchModel ( $model )
$model yii\base\Model|array|string|callable

モデルインスタンスまたはそのDI互換の設定。

例外 yii\base\InvalidConfigException

無効な設定の場合。

                public function setSearchModel($model)
{
    if (is_object($model) && !$model instanceof Model && !$model instanceof \Closure) {
        throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::className() . '` or its DI compatible configuration.');
    }
    $this->_searchModel = $model;
}

            
toArray() publicメソッド

定義されている場所: yii\base\ArrayableTrait::toArray()

モデルを配列に変換します。

このメソッドはまず、resolveFields()を呼び出すことで、結果の配列に含めるフィールドを特定します。次に、これらのフィールドを使用してモデルを配列に変換します。$recursiveがtrueの場合、埋め込まれたオブジェクトも配列に変換されます。埋め込まれたオブジェクトがyii\base\Arrayableを実装している場合、それぞれのネストされたフィールドが抽出され、toArray()に渡されます。

モデルがyii\web\Linkableインターフェースを実装している場合、結果の配列には、インターフェースで指定されたリンクのリストを参照する_link要素も含まれます。

public array toArray ( array $fields = [], array $expand = [], $recursive true )
$fields array

要求されているフィールド。空の場合、または'*'が含まれている場合、fields()で指定されたすべてのフィールドが返されます。フィールドは、ドットで区切られたネスト構造にすることができます(例:item.field.sub-field)。ネストされたフィールドを抽出するには、$recursiveをtrueにする必要があります。$recursiveがfalseの場合、ルートフィールドのみが抽出されます。

$expand array

エクスポートのために要求されている追加のフィールド。extraFields()で宣言されたフィールドのみが考慮されます。Expandも、ドットで区切られたネスト構造にすることができます(例:item.expand1.expand2)。ネストされたExpandを抽出するには、$recursiveをtrueにする必要があります。$recursiveがfalseの場合、ルートExpandのみが抽出されます。

$recursive boolean

埋め込まれたオブジェクトの配列表現を再帰的に返すかどうか。

戻り値 array

オブジェクトの配列表現。

                public function toArray(array $fields = [], array $expand = [], $recursive = true)
{
    $data = [];
    foreach ($this->resolveFields($fields, $expand) as $field => $definition) {
        $attribute = is_string($definition) ? $this->$definition : $definition($this, $field);
        if ($recursive) {
            $nestedFields = $this->extractFieldsFor($fields, $field);
            $nestedExpand = $this->extractFieldsFor($expand, $field);
            if ($attribute instanceof Arrayable) {
                $attribute = $attribute->toArray($nestedFields, $nestedExpand);
            } elseif ($attribute instanceof \JsonSerializable) {
                $attribute = $attribute->jsonSerialize();
            } elseif (is_array($attribute)) {
                $attribute = array_map(
                    function ($item) use ($nestedFields, $nestedExpand) {
                        if ($item instanceof Arrayable) {
                            return $item->toArray($nestedFields, $nestedExpand);
                        } elseif ($item instanceof \JsonSerializable) {
                            return $item->jsonSerialize();
                        }
                        return $item;
                    },
                    $attribute
                );
            }
        }
        $data[$field] = $attribute;
    }
    if ($this instanceof Linkable) {
        $data['_links'] = Link::serialize($this->getLinks());
    }
    return $recursive ? ArrayHelper::toArray($data) : $data;
}

            
trigger() publicメソッド

定義されている場所: yii\base\Component::trigger()

イベントをトリガーします。

このメソッドは、イベントの発生を表します。クラスレベルのハンドラーを含む、イベントにアタッチされたすべてのハンドラーを呼び出します。

public void trigger ( $name, yii\base\Event $event null )
$name string

イベント名

$event yii\base\Event|null

イベントインスタンス。設定されていない場合、デフォルトのyii\base\Eventオブジェクトが作成されます。

                public function trigger($name, Event $event = null)
{
    $this->ensureBehaviors();
    $eventHandlers = [];
    foreach ($this->_eventWildcards as $wildcard => $handlers) {
        if (StringHelper::matchWildcard($wildcard, $name)) {
            $eventHandlers[] = $handlers;
        }
    }
    if (!empty($this->_events[$name])) {
        $eventHandlers[] = $this->_events[$name];
    }
    if (!empty($eventHandlers)) {
        $eventHandlers = call_user_func_array('array_merge', $eventHandlers);
        if ($event === null) {
            $event = new Event();
        }
        if ($event->sender === null) {
            $event->sender = $this;
        }
        $event->handled = false;
        $event->name = $name;
        foreach ($eventHandlers as $handler) {
            $event->data = $handler[1];
            call_user_func($handler[0], $event);
            // stop further handling if the event is handled
            if ($event->handled) {
                return;
            }
        }
    }
    // invoke class-level attached handlers
    Event::trigger($this, $name, $event);
}

            
validate() publicメソッド

定義されている場所: yii\base\Model::validate()

データのバリデーション(検証)を実行します。

このメソッドは、現在の$scenarioに適用可能な検証ルールを実行します。ルールが現在適用可能かどうかを判断する基準は以下のとおりです。

  • ルールは、現在のシナリオに関連する属性に関連付けられている必要があります。
  • ルールは、現在のシナリオで有効である必要があります。

このメソッドは、実際の検証の前後にそれぞれbeforeValidate()afterValidate()を呼び出します。beforeValidate()がfalseを返す場合、検証はキャンセルされ、afterValidate()は呼び出されません。

検証中に見つかったエラーは、getErrors()getFirstErrors()、およびgetFirstError()を使用して取得できます。

public boolean validate ( $attributeNames null, $clearErrors true )
$attributeNames string[]|string|null

検証対象とする属性名、または属性名のリストです。このパラメータが空の場合、適用可能な検証ルールにリストされている属性がすべて検証されます。

$clearErrors boolean

検証を実行する前に、clearErrors() を呼び出すかどうか

戻り値 boolean

エラーなしで検証が成功したかどうか。

例外 yii\base\InvalidArgumentException

現在のシナリオが不明な場合。

                public function validate($attributeNames = null, $clearErrors = true)
{
    if ($clearErrors) {
        $this->clearErrors();
    }
    if (!$this->beforeValidate()) {
        return false;
    }
    $scenarios = $this->scenarios();
    $scenario = $this->getScenario();
    if (!isset($scenarios[$scenario])) {
        throw new InvalidArgumentException("Unknown scenario: $scenario");
    }
    if ($attributeNames === null) {
        $attributeNames = $this->activeAttributes();
    }
    $attributeNames = (array)$attributeNames;
    foreach ($this->getActiveValidators() as $validator) {
        $validator->validateAttributes($this, $attributeNames);
    }
    $this->afterValidate();
    return !$this->hasErrors();
}

            
validateAttributeCondition() protectedメソッド

定義位置: yii\data\DataFilter::validateAttributeCondition()

特定の属性の検索条件を検証します。

protected void validateAttributeCondition ( $attribute, $condition )
$attribute string

検索属性名。

$condition mixed

検索条件。

                protected function validateAttributeCondition($attribute, $condition)
{
    $attributeTypes = $this->getSearchAttributeTypes();
    if (!isset($attributeTypes[$attribute])) {
        $this->addError($this->filterAttributeName, $this->parseErrorMessage('unknownAttribute', ['attribute' => $attribute]));
        return;
    }
    if (is_array($condition)) {
        $operatorCount = 0;
        foreach ($condition as $rawOperator => $value) {
            if (isset($this->filterControls[$rawOperator])) {
                $operator = $this->filterControls[$rawOperator];
                if (isset($this->operatorTypes[$operator])) {
                    $operatorCount++;
                    $this->validateOperatorCondition($rawOperator, $value, $attribute);
                }
            }
        }
        if ($operatorCount > 0) {
            if ($operatorCount < count($condition)) {
                $this->addError($this->filterAttributeName, $this->parseErrorMessage('invalidAttributeValueFormat', ['attribute' => $attribute]));
            }
        } else {
            // attribute may allow array value:
            $this->validateAttributeValue($attribute, $condition);
        }
    } else {
        $this->validateAttributeValue($attribute, $condition);
    }
}

            
validateAttributeValue() protectedメソッド

定義位置: yii\data\DataFilter::validateAttributeValue()

modelの範囲内で属性値を検証します。

protected void validateAttributeValue ( $attribute, $value )
$attribute string

属性名。

$value mixed

属性値。

                protected function validateAttributeValue($attribute, $value)
{
    $model = $this->getSearchModel();
    if (!$model->isAttributeSafe($attribute)) {
        $this->addError($this->filterAttributeName, $this->parseErrorMessage('unknownAttribute', ['attribute' => $attribute]));
        return;
    }
    $model->{$attribute} = $value === $this->nullValue ? null : $value;
    if (!$model->validate([$attribute])) {
        $this->addError($this->filterAttributeName, $model->getFirstError($attribute));
        return;
    }
}

            
validateBlockCondition() protectedメソッド

定義位置: yii\data\DataFilter::validateBlockCondition()

単一の条件からなるブロック条件を検証します。

これは、notなどの演算子をカバーしています。

protected void validateBlockCondition ( $operator, $condition )
$operator string

生の演算子制御キーワード。

$condition mixed

生の条件。

                protected function validateBlockCondition($operator, $condition)
{
    $this->validateCondition($condition);
}

            
validateCondition() protectedメソッド

定義位置: yii\data\DataFilter::validateCondition()

フィルタ条件を検証します。

protected void validateCondition ( $condition )
$condition mixed

生のフィルタ条件。

                protected function validateCondition($condition)
{
    if (!is_array($condition)) {
        $this->addError($this->filterAttributeName, $this->parseErrorMessage('invalidFilter'));
        return;
    }
    if (empty($condition)) {
        return;
    }
    foreach ($condition as $key => $value) {
        $method = 'validateAttributeCondition';
        if (isset($this->filterControls[$key])) {
            $controlKey = $this->filterControls[$key];
            if (isset($this->conditionValidators[$controlKey])) {
                $method = $this->conditionValidators[$controlKey];
            }
        }
        $this->$method($key, $value);
    }
}

            
validateConjunctionCondition() protectedメソッド

定義位置: yii\data\DataFilter::validateConjunctionCondition()

複数の独立した条件からなる複合条件を検証します。

これは、andorなどの演算子をカバーしています。

protected void validateConjunctionCondition ( $operator, $condition )
$operator string

生の演算子制御キーワード。

$condition mixed

生の条件。

                protected function validateConjunctionCondition($operator, $condition)
{
    if (!is_array($condition) || !ArrayHelper::isIndexed($condition)) {
        $this->addError($this->filterAttributeName, $this->parseErrorMessage('operatorRequireMultipleOperands', ['operator' => $operator]));
        return;
    }
    foreach ($condition as $part) {
        $this->validateCondition($part);
    }
}

            
validateFilter() publicメソッド

定義位置: yii\data\DataFilter::validateFilter()

フィルタ条件の仕様と一致するようにフィルタ属性値を検証します。

public void validateFilter ( )

                public function validateFilter()
{
    $value = $this->getFilter();
    if ($value !== null) {
        $this->validateCondition($value);
    }
}

            
validateMultiple() public staticメソッド

定義位置: yii\base\Model::validateMultiple()

複数のモデルを検証します。

このメソッドは、すべてのモデルを検証します。検証されるモデルは、同じ型でも異なる型でもかまいません。

public static boolean validateMultiple ( $models, $attributeNames null )
$models array

検証対象のモデル

$attributeNames array|null

検証対象とする属性名のリストです。このパラメータが空の場合、適用可能な検証ルールにリストされている属性がすべて検証されます。

戻り値 boolean

すべてのモデルが有効かどうか。1つ以上のモデルに検証エラーがある場合、falseが返されます。

                public static function validateMultiple($models, $attributeNames = null)
{
    $valid = true;
    /* @var $model Model */
    foreach ($models as $model) {
        $valid = $model->validate($attributeNames) && $valid;
    }
    return $valid;
}

            
validateOperatorCondition() protectedメソッド

定義位置: yii\data\DataFilter::validateOperatorCondition()

演算子条件を検証します。

protected void validateOperatorCondition ( $operator, $condition, $attribute null )
$operator string

生の演算子制御キーワード。

$condition mixed

属性条件。

$attribute string|null

属性名。

                protected function validateOperatorCondition($operator, $condition, $attribute = null)
{
    if ($attribute === null) {
        // absence of an attribute indicates that operator has been placed in a wrong position
        $this->addError($this->filterAttributeName, $this->parseErrorMessage('operatorRequireAttribute', ['operator' => $operator]));
        return;
    }
    $internalOperator = $this->filterControls[$operator];
    // check operator type :
    $operatorTypes = $this->operatorTypes[$internalOperator];
    if ($operatorTypes !== '*') {
        $attributeTypes = $this->getSearchAttributeTypes();
        $attributeType = $attributeTypes[$attribute];
        if (!in_array($attributeType, $operatorTypes, true)) {
            $this->addError($this->filterAttributeName, $this->parseErrorMessage('unsupportedOperatorType', ['attribute' => $attribute, 'operator' => $operator]));
            return;
        }
    }
    if (in_array($internalOperator, $this->multiValueOperators, true)) {
        // multi-value operator:
        if (!is_array($condition)) {
            $this->addError($this->filterAttributeName, $this->parseErrorMessage('operatorRequireMultipleOperands', ['operator' => $operator]));
        } else {
            foreach ($condition as $v) {
                $this->validateAttributeValue($attribute, $v);
            }
        }
    } else {
        // single-value operator :
        $this->validateAttributeValue($attribute, $condition);
    }
}