PHPackages                             sorokinmedia/yii2-treeview - 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. [Framework](/categories/framework)
4. /
5. sorokinmedia/yii2-treeview

ActiveYii2-extension[Framework](/categories/framework)

sorokinmedia/yii2-treeview
==========================

Tree view for Yii2

1.4.1(7y ago)1191BSD-3-ClausePHPCI failing

Since Jul 24Pushed 6y ago5 watchersCompare

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

READMEChangelog (6)Dependencies (2)Versions (8)Used By (0)

yii2-treeview
=============

[](#yii2-treeview)

[![Total Downloads](https://camo.githubusercontent.com/7922f41fbd3963dfee0b3e8a5ffedc3c57d0a1418b642f90f7b8612fb6549979/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736f726f6b696e6d656469612f796969322d74726565766965772e737667)](https://packagist.org/packages/sorokinmedia/yii2-treeview)

---

Sorokin.Media repository

---

Компонент позволяет строить деревья объектов для заданной сущности.

AR модель должна содержать 2 обязательных атрибута: `(int) parent_id`, `(bool) has_child`.

В модель необходимо добавить атрибут `$level` - в БД добавлять не нужно.

AR модель, которая имеет дочернюю сущность с деревом, должна имплементировать интерфейс `TreeViewModelInterface` и реализовывать метод `getChildModels(int $parent_id)`.

AR модель, которая внутри себя имеет иерархическую структуру, должна имплементрировать интерфейс `TreeViewModelStaticInterface` и реализовывать статический метод `getChildModelsStatic(int $parent_id)`.

Пример файла основной модели (в данной случае CourseLesson), дерево строится для дочерней (в данном случае CourseLessonComment):

```
class CourseLesson extends CourseLessonAR implements TreeViewModelInterface
{
    public $level;

    public function getChildModels(int $parent_id)
    {
        return CourseLessonComment::find()
            ->where(['lesson_id' => $this->id, 'parent_id' => $parent_id])
            ->orderBy(['created_at' => SORT_DESC])
            ->all();
    }
}
```

Далее необходимо добавить класс дерева комментариев. Он должен быть унаследован от абстракта `AbstractTreeView`.

Тело класса можно оставить пустым, либо переопределить статический методы:

- `public static function makeTree(TreeViewModelInterface $model, int $parent_id = 0, int $level = 0): array` - вернет массив моделей в иерархическом порядке
- `public static function makeTreeArray(TreeViewModelInterface $model, int $parent_id = 0, string $level = ''): array` - вернет масси объектов {id, name} в иерархическом порядке (для селекта)
- `public static function makeTreeStatic(string $class_name, int $parent_id = 0, int $level = 0, $filter = null): array` - вернет масси моделей в иерархическом порядке. вариант для статического использования
- `public static function makeTreeStaticArray(string $class_name, int $parent_id = 0, string $level = ''): array` - вернет масси объектов {id, name} в иерархическом порядке (для селекта). вариант для статического использования

Например `CourseLessonCommentTree`:

```
use sorokinmedia\treeview\AbstractTreeView;

class CourseLessonCommentTree extends AbstractTreeView
{

}
```

Пример файла модели, которая имеет внутри себя иерархическую структуру:

```
class PromoCodeCategory extends AbstractPromoCodeCategory implements TreeViewModelStaticInterface
{
    public $level;

    public static function getChildModelsStatic(int $parent_id, $filter = null)
    {
        return static::find()
            ->where(['parent_id' => $parent_id])
            ->orderBy(['name' => SORT_ASC])
            ->all();
    }
}
```

Пример класса с деревом:

```
use sorokinmedia\treeview\AbstractTreeView;

class PromoCodeCategoryTree extends AbstractTreeView
{

}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~17 days

Total

6

Last Release

2766d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6071315?v=4)[Ruslan Gilyazetdinov](/maintainers/Ma3oBblu)[@Ma3oBblu](https://github.com/Ma3oBblu)

---

Top Contributors

[![Ma3oBblu](https://avatars.githubusercontent.com/u/6071315?v=4)](https://github.com/Ma3oBblu "Ma3oBblu (20 commits)")

---

Tags

treeyii2active-recordyii 2

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sorokinmedia-yii2-treeview/health.svg)

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

###  Alternatives

[yiisoft/yii2-redis

Redis Cache, Session and ActiveRecord for the Yii framework

48011.7M245](/packages/yiisoft-yii2-redis)[yiisoft/yii2-elasticsearch

Elasticsearch integration and ActiveRecord for the Yii framework

4371.9M15](/packages/yiisoft-yii2-elasticsearch)[yiisoft/yii2-mongodb

MongoDB extension for the Yii framework

3312.1M45](/packages/yiisoft-yii2-mongodb)[yiisoft/yii2-sphinx

Sphinx full text search engine extension for the Yii framework

180997.7k5](/packages/yiisoft-yii2-sphinx)[vova07/yii2-start

Yii2-Start it's a small Yii 2 application template for your fast project start.

26811.1k7](/packages/vova07-yii2-start)[elisdn/yii2-composite-form

Nested forms base class for Yii2 Framework.

53211.8k8](/packages/elisdn-yii2-composite-form)

PHPackages © 2026

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