consultnn/yii2-behaviors

1.0.3 2016-03-08 20:00 UTC

README

Use consultnn/yii2-validators instead AttributeTypeBehavior

yii2-behaviors

Extension of the class yii\base\Behavior

###Class AttributeTypeBehavior to converts attribute for all simple types and mongoDb types.
Number and boolean type taken from the corresponding attribute validator

Example of a call from the model.
    public function behaviors()
    {
        return [
            [
                'class' => AttributeTypeBehavior::className(),
                'attributes' => [
                    '_id' => AttributeTypeBehavior::TYPE_MONGO_ID,
                    'attribute1' => [AttributeTypeBehavior::TYPE_ARRAY_OF => AttributeTypeBehavior::TYPE_INTEGER]
                ]
            ]
        ];
    }

Default events ActiveRecord::EVENT_BEFORE_INSERT, ActiveRecord::EVENT_BEFORE_UPDATE

Example add convert MongoDate type.

Add attributes => ['date' => 'MongoDate']
Add a method to the class AttributeTypeBehavior:

    private function setMongoDate(&$value)
    {
        $value = new \MongoDate(strtotime($value));
    }

###Class TreeViewBehavior to dynamically update the model attributes with the use of plug-in jstree Events ActiveRecord::EVENT_BEFORE_INSERT, ActiveRecord::EVENT_BEFORE_UPDATE, ActiveRecord::EVENT_BEFORE_DELETE