Giter VIP home page Giter VIP logo

yii2-classifier's Introduction

Classifier component for Yii2

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

yii2-classifier's People

Contributors

ivokund avatar ptheofan avatar viilveer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.