PHPackages                             kr0lik/yii2-ltree - 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. kr0lik/yii2-ltree

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

kr0lik/yii2-ltree
=================

Yii2 traits for postgresql ltree module

2.1.0(6y ago)12.0kMITPHPPHP &gt;=7.0

Since Apr 25Pushed 6y ago1 watchersCompare

[ Source](https://github.com/kr0lik/yii2-ltree)[ Packagist](https://packagist.org/packages/kr0lik/yii2-ltree)[ RSS](/packages/kr0lik-yii2-ltree/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (0)

yii2-ltree
==========

[](#yii2-ltree)

Postgresql ltree traits for yii2

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

[](#installation)

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

Either run

```
composer require --prefer-dist kr0lik/yii2-ltree

```

or add

```
"kr0lik/yii2-ltree": "*"

```

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

Usage
-----

[](#usage)

Required `id` field in model.

Extension ltree must be instaled with schema `public`. You can change it by changing static property `Ql::$ltreeSchema`

By default path field in table must be named as `lpath`You can change it by changing property `ltreePathField` in traits

Add \\kr0lik\\ltree\\LtreeActiveRecordTrait to your ActiveRecord

Available methods:

```
/**
 * Get path of $model
 */
$model->getLPath(): string

/**
 * Get level of $model
 * retutn 1 - is root
 * retutn 0 - cant get level
 */
$model->getLevel(): int;

/**
 * Check if $model is root(0 level)
 */
$model->isRoot(): bool;

/**
 * Check if $model is first level(After Root)
 */
$model->isFirstLevel(): bool;

/**
 * Get childrens of $model
 *
 * @param int $level DEFAULT 0
 * $level = 0 - get all childs
 * $level = n - get n level childs
 */
$model->getChildrens($level): ActiveQuery;

/**
 * Get parents of $model
 *
 * @param int $level DEFAULT 0
 * $level = 0 - get all parents
 * $level = n - get n level parents
 */
$model->getParents($level): ActiveQuery;

/**
 * Get Next categories of $model in $model level
 */
$model->getNext(): ActiveQuery;

/**
 * Get Previous categories of $model in $model level
 */
$model->getPrevious(): ActiveQuery;

/**
 * Get categories in $model level
 *
 * @return ActiveQuery
 */
$model->getNearest(): ActiveQuery;

/**
 * Remove $model from db
 */
$model->delete(): bool;

/**
 * Move/insert $model into $anotherModel to the end
 *
 * @param self $anotherModel
 */
$model->appendTo($anotherModel): void;

/**
 * Move/insert $model into $anotherModel to the start
 *
 * @param self $anotherModel
 */
$model->prependTo($anotherModel): void;

/**
 * Move/insert $model after $anotherModel
 *
 * @param self $anotherModel
 */
$model->after($anotherModel): void;

/**
 * Move/insert $model before $anotherModel
 *
 * @param self $anotherModel
 */
$model->before($anotherModel): void;

/**
 * Save $model as root
 */
$model->makeRoot(): void
```

Add \\kr0lik\\ltree\\LtreeQueryTrait to your ActiveQuery

Available methods:

```
/**
 * Sort by path
 *
 * @param int $sort DEFAULT SORT_ASC
 */
Model::find()->sorted($sort): ActiveQuery;

/**
 * Get all without root
 */
Model::find()->notRoot(): ActiveQuery;

/**
 * Get root only
 */
Model::find()->root(): ActiveQuery;

/**
 * Get models by $path
 *
 * @param string $path
 * @param boolean $recursive DEFAULT true
 * If $recursive == true then get all models where path field value starts from $path(with all childrens)
 */
Model::find()->byPath($path, $recursive): ActiveQuery;

/**
 * Get not equal path
 *
 * @param string $path
 */
Model::find()->not($path): ActiveQuery;

/**
 * Get closest models on branch
 *
 * @param string $path
 */
Model::find()->closest($path): ActiveQuery;

/**
 * Join parents
 *
 * @param int $level DEFAULT 0
 * $level = 0 - get all parents
 * $level = n - get n levels of parents start from $this level
 * @param string $joinType DEFAULT 'LEFT JOIN'
 */
Model::find()>joinParents($level, $joinType): ActiveQuery;

/**
 * Join childrens
 *
 * @param int $level DEFAULT 0
 * $level = 0 - get all childrens
 * $level = n - get n levels of childrens start from $this level
 * @param string $joinType DEFAULT 'LEFT JOIN'
 */
Model::find()->joinChildrens($level, $joinType): ActiveQuery;

/**
 * Set start level
 *
 * @param int $level
 */
Model::find()->startLevel($level): ActiveQuery;

/**
 * Set end level
 *
 * @param int $level
 */
Model::find()->endLevel($level): ActiveQuery;

/**
 * Set level
 *
 * @param int $level
 */
Model::find()->level($level): ActiveQuery;

/**
 * Get all as tree
 *
 * @return array
 */
Model::find()->tree(): array;
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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 ~120 days

Recently: every ~113 days

Total

7

Last Release

2265d ago

Major Versions

1.0.2 → 2.0.02020-03-30

### Community

Maintainers

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

---

Top Contributors

[![kr0lik](https://avatars.githubusercontent.com/u/12142976?v=4)](https://github.com/kr0lik "kr0lik (82 commits)")

---

Tags

postgresqlpostgresyii2ltree

### Embed Badge

![Health badge](/badges/kr0lik-yii2-ltree/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[nanson/yii2-postgis

Yii2-extension to work with postgis data

1852.9k](/packages/nanson-yii2-postgis)[imanilchaudhari/yii2-currency-converter

This extension will help to find out current currency conversion rate.

1911.7k](/packages/imanilchaudhari-yii2-currency-converter)

PHPackages © 2026

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