insolita / yii2-form-prefiller
Remember user-filled form data
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.0
- nesbot/carbon: ^2.0
- yiisoft/yii2: ~2.0.13
Requires (Dev)
- codeception/codeception: ^3.1
- codeception/specify: 0.4.*
- codeception/verify: 0.4.*
- vlucas/phpdotenv: *
- yiisoft/yii2-redis: 2.*
This package is auto-updated.
Last update: 2024-11-27 01:41:36 UTC
README
Remember user-filled form data, prefill forms with remembered data Usefully for remember filter/sorting preferences, or make some sticky attributes
Installation
The preferred way to install this extension is through composer.
Either run
composer require --prefer-dist insolita/yii2-form-prefiller "~1.0"
or add
"insolita/yii2-form-prefiller": "~0.0.1"
to the require section of your composer.json
file.
Usage
Once the extension is installed, configure component :
'components'=>[ 'prefiller' => [ 'class' => \insolita\prefiller\FormPrefiller::class, 'storage' => [ //one of storage types - db,session,cookie,redis supported 'class' => \insolita\prefiller\storages\CookieStorage::class, ], ], ]
Support ActiveRecord models,yii\base\Model,DummyModel
Remember $model data in storage
Yii::$app->prefiller->persist($model, new PrefillConfig([]));
Fill $model from storage
Yii::$app->prefiller->fillFromStorage($model, new PrefillConfig([
'skipFromStorageAttributes'=>['someAttr'],
'validateStorage'=>false
]));
Fill model from request->fillFromStorage->fillDefaults->persist if request update model
$filter = new DummyModel(['page','sort','sortOrder','searchQuery','viewMode']);
Yii::$app->prefiller->fill($filter, new PrefillConfig([
'method'=>'get',
'defaults'=>['sort'=>'price','sortOrder'=>'desc','viewMode'=>'grid']
'skipFromRequestAttributes'=>['searchQuery'],
'validateRequest'=>true
]));