Search by

handcode / yii2-active-record-typecast-behavior

handcode

TypeCast Behavior for yii2 ActiveRecords which can be used to ensure attribute types match db schema types

Package info

github.com/handcode/yii2-active-record-typecast-behavior

Type:yii2-extension

pkg:composer/handcode/yii2-active-record-typecast-behavior

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-11-13 19:55 UTC

This package is auto-updated.

Last update: 2026-11-13 19:59:53 UTC


README

This behavior can be used to typecast yii2 ActiveRecord attribute values according to the db->schema types

Why?

To automate the filters required to solve the "int-cols are always dirty if submitted via http" problem.

see:

config

the attribute typecast is done by calling \yii\validators\FilterValidator with defined filter callback according to db schema phpType all attributes with types not defined in the typeFilter array of the behavior will be ignored.

The default typeFilter definition is:

public $typeFilter = [
    'integer' => 'intval',
    'float'   => 'floatval'
];