2017 © Pedro Peláez
 

yii2-extension yii2-options

Yii2 Extenstion for set options

image

porcelanosa/yii2-options

Yii2 Extenstion for set options

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

WARNING! UNDER DEVELOPMENT Total Downloads, (*1)

Installation

This document will guide you through the process of installing yii2-options using composer. Installation is a quick and easy several step process., (*2)

NOTE: Before we start make sure that you have properly configured db application component., (*3)

Step 1: Download using composer

Add yii2-options to the require section of your composer.json file:, (*4)

{
    "require": {
        "porcelanosa/yii2-options": "dev-master"
    }
}

And run following command to download extension using composer:, (*5)

$ php composer.phar update

Step 2: Configure your application

Add options module to both web and console config files as follows:, (*6)

...
'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, (*7)

'components'     => [
    'request' => [
        'parsers' => [
            'application/json' => 'yii\web\JsonParser',
        ]
    ],

Configure Karik-V module, (*8)

'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:, (*9)

$ php yii migrate/up --migrationPath=@vendor/porcelanosa/yii2-options/migrations

Menu items, (*10)


['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, (*11)

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:, (*12)

'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, (*13)

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, (*14)

<? echo \porcelanosa\yii2options\ChildOptionsWidget::widget(
    [
        'model'        => $model,
        'behaviorName' => 'childOptionsBehavior'
    ] );
?>

The Versions

01/08 2016

dev-master

9999999-dev https://github.com/porcelanosa/yii2-options

Yii2 Extenstion for set options

  Sources   Download

MIT

The Requires

 

by Alex Porcelanosa

yii2 yii yii 2