porcelanosa / yii2-options
Yii2 Extenstion for set options
Installs: 15
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.4.0
- bower-asset/sortablejs: *
- bower-asset/vue: *
- bower-asset/vue-resource: *
- kartik-v/yii2-grid: @dev
- porcelanosa/yii2-toggle-column: *
- vova07/yii2-imperavi-widget: *
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2025-01-04 20:31:20 UTC
README
WARNING! UNDER DEVELOPMENT Installation
This document will guide you through the process of installing yii2-options using composer. Installation is a quick and easy several step process.
NOTE: Before we start make sure that you have properly configured db application component.
Step 1: Download using composer
Add yii2-options to the require section of your composer.json file:
{ "require": { "porcelanosa/yii2-options": "dev-master" } }
And run following command to download extension using composer:
$ php composer.phar update
Step 2: Configure your application
Add options module to both web and console config files as follows:
... 'modules' => [ ... 'options' => [ 'class' => 'porcelanosa\yii2options\Module', 'layout' => '@app/modules/admin/views/layouts/main', 'model_path' => '@app/modules/admin/models/*.php', // models php files 'modelNamespace' => 'app\modules\admin\models\', // models namespace 'fileUrl' => '/storage/uploads/richtext/files', 'filePath' => '@storage/uploads/richtext/files', 'imageUrl' => '/storage/uploads/richtext/images', 'imagePath' => '@storage/uploads/richtext/images', ], ... ], ...
Configure request parser
'components' => [ 'request' => [ 'parsers' => [ 'application/json' => 'yii\web\JsonParser', ] ],
Configure Karik-V module
'modules' => [ 'gridview' => [ 'class' => '\kartik\grid\Module' ] ],
Step 3: Updating database schema
After you downloaded and configured yii2-options, the last thing you need to do is updating your database schema by applying the migration:
$ php yii migrate/up --migrationPath=@vendor/porcelanosa/yii2-options/migrations
Menu items
['label' => Yii::t('app', 'ADMIN_NAV_STATUS_TYPES'), 'url' => ['/options/optiontypes/index']], ['label' => Yii::t('app', 'ADMIN_NAV_OPTIONS_LIST'), 'url' => ['/options/optionslist/index']],
Step 4: Adjust models
Add behavior
use porcelanosa\yii2options\models\Options; use porcelanosa\yii2options\OptionsBehavior; use porcelanosa\yii2options\ChildOptionsBehavior; use porcelanosa\yii2options\components\helpers\MyHelper; public function behaviors() { return [ 'optionsBehavior' => [ 'class' => OptionsBehavior::className(), 'model_name' => $this::className(), // convert className to model name without namespace 'uploadImagePath' => Yii::getAlias( '@webroot' ) . '/uploads/cats/', // alias of upload folder 'uploadImageUrl' => Yii::getAlias( '@web' ) . '/uploads/cats/', // alias of upload folder // admin application url without end slash 'appUrl' => '/backend' ], }
For Child behavior for example in Items model add:
'childOptionsBehavior' => [ 'class' => ChildOptionsBehavior::className(), 'model_name' => $this::className(), 'parent_model_name' => '\common\models\Cats', // relation name for parent model, e.q. if relation function is getCat() - relation name is "cat" 'parent_relation' => 'cat', 'uploadImagePath' => Yii::getAlias( '@storage' ) . '/uploads/items/', // alias of upload folder 'uploadImageUrl' => '/storage/uploads/items/', // Yii::getAlias( '@storageUrl' ) . alias of upload folder // admin application url without end slash 'appUrl' => '/backend' ],
Add binding paramters
public $modelFrontName = 'Категории'; //if not define $modelFrontName - not show in dropdown list in optionslist controller // in Parent model define Child model public $childModels = [ 'Items'=>'Товары в категории', ];
Step 5: Show options in admin view
<? echo \porcelanosa\yii2options\OptionsWidget::widget( [ 'model' => $model, 'behaviorName' => 'optionsBehavior' ] ); ?>
or for Child Options
<? echo \porcelanosa\yii2options\ChildOptionsWidget::widget( [ 'model' => $model, 'behaviorName' => 'childOptionsBehavior' ] ); ?>