PHPackages                             jakharbek/yii2-categories - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jakharbek/yii2-categories

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

jakharbek/yii2-categories
=========================

Categories

3516PHP

Since Feb 27Pushed 8y agoCompare

[ Source](https://github.com/jakharbek/yii2-categories)[ Packagist](https://packagist.org/packages/jakharbek/yii2-categories)[ RSS](/packages/jakharbek-yii2-categories/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Categories
==========

[](#categories)

Categories

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist jakharbek/yii2-categories "*"

```

or add

```
"jakharbek/yii2-categories": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by :

You need to connect a controller or an action to the controller

controller

```
    'controllerMap' => [
        'categories' => 'jakharbek\categories\controllers\CategoriesController'
    ],
```

action

```
   public function actions()
       {
           return [
               'categories' => [
                   'class' => 'jakharbek\categories\actions\CategoriesAction'
               ]
           ];
       }
```

You must have an extension

```
jakharbek/yii2-langs

```

You need to connect i18n for translations

```
 'jakhar-categories' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@vendor/jakharbek/yii2-categories/src/messages',
                    'sourceLanguage' => 'en',
                    'fileMap' => [
                        'jakhar-categories'       => 'main.php',
                    ],
                ],
```

and migrate the database

```
yii migrate --migrationPath=@vendor/jakharbek/yii2-categories/src/migrations
```

Update (Active Record) - Single
-------------------------------

[](#update-active-record---single)

example with Posts elements

You must connect behavior to your database model (Active Record)

```
 'category_model'=> [
                        'class' => CategoryModelBehavior::className(),
                        'attribute' => 'categoriesform',
                        'separator' => ',',
                        ],
```

example

```
use jakharbek\categories\behaviors\CategoryModelBehavior;

        class Posts extends ActiveRecord
        {
            private $_categoriesform;

            public function behaviors()
            {
                 ...
                        'category_model'=> [
                        'class' => CategoryModelBehavior::className(),
                        'attribute' => 'categoriesform',
                        'separator' => ',',
                        ],
                 ...
            }

            ...

            public function getCategoriesform(){
                return $this->_categoriesform;
            }
            public function setCategoriesform($value){
                return $this->_categoriesform = $value;
            }
        }
```

Afterwards you need to add your widget form.

```
jakharbek\categories\widgets\CategoriesWidget::widget
```

example

```
echo jakharbek\categories\widgets\CategoriesWidget::widget([
  'selected' => $model->categoriesSelected(),
  'model_db' => $model,'name' => 'Posts[categoriesform]'
  ]);
```

and of course do not forget to prescribe links for your model

```
    public function getPostscategories()
    {
        return $this->hasMany(Postscategories::className(), ['post_id' => 'post_id']);
    }

    public function getCategories()
    {
        return $this->hasMany(Categories::className(), ['id' => 'id'])->viaTable('postscategories', ['post_id' => 'post_id']);
    }
```

It's all!

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a2721d46252bc78f08af8c419a8ac814b6b79c9764696686e13e119e4f291f95?d=identicon)[javharbek](/maintainers/javharbek)

---

Top Contributors

[![jakharbek](https://avatars.githubusercontent.com/u/31648260?v=4)](https://github.com/jakharbek "jakharbek (1 commits)")

### Embed Badge

![Health badge](/badges/jakharbek-yii2-categories/health.svg)

```
[![Health](https://phpackages.com/badges/jakharbek-yii2-categories/health.svg)](https://phpackages.com/packages/jakharbek-yii2-categories)
```

###  Alternatives

[unleash/client

633.1M8](/packages/unleash-client)[hyperf/watcher

Hot reload watcher for Hyperf

17846.7k27](/packages/hyperf-watcher)[datatables.net/datatables.net-dt

DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML table. This is DataTables with styling for \[DataTables\](https://datatables.net/)

1835.1k15](/packages/datatablesnet-datatablesnet-dt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
