opus-online/yii2-classifier

There is no license information available for the latest version (v1.1.5) of this package.

Classifier component for Yii2

Installs: 5 025

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 8

Forks: 4

Open Issues: 3

Type:yii2-extension

v1.1.5 2019-07-15 11:56 UTC

This package is auto-updated.

Last update: 2022-09-15 20:50:08 UTC


README

Provides simple access to classifiers using Active Record.

Installation

The esiest way to obtain the code is using Composer: just modify your composer.json to add a custom repository (linking to this project) and require the libary.

{
	"require": {
		"opus-online/yii2-classifier": "dev-master"
	}
}

Configuration

Just add the main class as a component to your Yii2 project common configuration

'classifier' => [
    'class' => '\opus\classifier\Classifier',
],

And the classifier controller to your console configuration

    'controllerMap' => [
        'classifier' => \opus\classifier\ClassifierController::class,
    ],

And create the necessary tables using the command

php yii migrate --migrationPath=@vendor/opus-online/yii2-classifier/migrations

With default configuration, 3 tables are created (you can change the table names in the configuration):

  • ym_util_classifier
  • ym_util_classifier_value
  • ym_util_classifier_value_i18n

Definition

Define your classifiers in a yaml file like this:

MY_CLASSIFIER:
  name: Label for the classifier
  system: 1 # (1/0, system variables should not be changed by users)
  values:
    MY_VALUE_1: [Value label, OptionalCustomAttributes]
    MY_VALUE_2: [Value 2]
  description: Some optional description
GENDER:
  name: Gender
  values:
    MALE: [Male]
    FEMALE: [Female]
    OTHER: [Other]

And import them into the database using the command

php yii classifier/update @alias/to/classifiers.yml

Usage

// retrieve a classifier value by ID or by CODE
$label = \Yii::$app->classifier->getValue(3)->name;
$id = \Yii::$app->classifier->getValue('CLASSIFIER_CODE', 'VALUE_CODE')->id;

// retrieve a list of values by classifier ID or CODE
$listOfObjects = \Yii::$app->classifier->getList(14);
$simpleList = \Yii::$app->classifier->getList('MY_CODE', true);

Changelog

1.1.1

  • Fixed PHP Notice bug when using caching
  • Fixed PHP Notice bug when using classifiers without values
  • Fixed classifier value ordering bug

1.1

  • Added Yaml importer
  • Added PSR4 namespaces
  • Removed models, added direct SQL access
  • Added proper migrations