PHPackages                             andrewdanilov/yii2-helpers - 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. andrewdanilov/yii2-helpers

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

andrewdanilov/yii2-helpers
==========================

Various helpers

1.0.22(2y ago)11064MITPHPPHP &gt;=7.0

Since Apr 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/AndrewDanilov/yii2-helpers)[ Packagist](https://packagist.org/packages/andrewdanilov/yii2-helpers)[ RSS](/packages/andrewdanilov-yii2-helpers/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (24)Used By (4)

Yii2 Helpers
============

[](#yii2-helpers)

Various helpers

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

[](#installation)

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

Either run

```
composer require andrewdanilov/yii2-helpers "~1.0.0"

```

or add

```
"andrewdanilov/yii2-helpers": "~1.0.0"

```

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

Usage
=====

[](#usage)

ModelHelper
-----------

[](#modelhelper)

**ModelHelper::cleanLoadedValues()**

Обрабатывает массив с загружаемыми в модель значениями атрибутов по заданным правилам. Правила очистки задаются для конкретных атрибутов в массиве $attribute\_rules:

```
$attribute_rules = [
  'name' => [ModelHelper::ATTR_RULE_STRIP_TAGS],
  'text' => [ModelHelper::ATTR_RULE_CLEAN_JS, ModelHelper::ATTR_RULE_STRIP_TAGS],
  '' => [, , , ...],
  '*' => [, ...], // для всех атрибутов, даже если для них уже применялось правило
  '?' => [, ...], // только для атрибутов, для которых не указано правило
];
```

Набор правил применяется, если значение элемента массива `$values`соответствующего атрибуту является строкой. Если значение - массив, то набор правил будет рекурсивно применен ко всем вложенным строковым значениям элементов массива, независимо от имен их ключей. Глубина вложенности неограничена.

Метод `ModelHelper::cleanLoadedValues()` можно применять в модели, например, переписав базовый метод `\yii\base\Model::setAttributes()`следующим образом:

```
public function setAttributes($values, $safeOnly = true)
{
    $values = ModelHelper::cleanLoadedValues($values, [
        'title' => [ModelHelper::ATTR_RULE_STRIP_TAGS],
        'text' => [ModelHelper::ATTR_RULE_CLEAN_JS],
    ]);
    parent::setAttributes($values, $safeOnly);
}
```

Правило `ModelHelper::ATTR_RULE_CLEAN_JS` удалит из значения атрибута все теги `` как самозакрывающиеся, так и обычные, как содержащие скрипт в теле тега, так и в html-атрибуте src.

Правило `ModelHelper::ATTR_RULE_STRIP_TAGS` удалит из значения атрибута все html-теги, применив к нему функцию strip\_tags.

Правило `ModelHelper::ATTR_RULE_HTML_SPECIAL_CHARS` заменит в значении атрибута все html сущности на их &amp;-эквиваленты с помощью функции `htmlspecialchars()`.

**ModelHelper::getFirstError()**

Возвращает первую ошибку, возникшую в модели в виде строки или пустую строку, если ошибок нет.

```
$model = new MyModel();
$model->some_attr = 'some_wrong_value';
$model->validate();
echo \andrewdanilov\helpers\ModelHelper::getFirstError($model);
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity61

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

Recently: every ~188 days

Total

23

Last Release

809d ago

PHP version history (2 changes)1.0.1PHP &gt;=5.6.0

1.0.19PHP &gt;=7.0

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

helpersnestedobjecttextyii2extensionCKEditorcategorydatepickerprises

### Embed Badge

![Health badge](/badges/andrewdanilov-yii2-helpers/health.svg)

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

###  Alternatives

[gilek/yii2-gtreetable

yii2-gtreetable is an extension of Yii 2 Framework, which is wrapper for bootstrap-gtreetable plug-in, on the other hand it provides functionality which allows to save the nodes states into database.

4111.8k](/packages/gilek-yii2-gtreetable)[yiier/yii2-helpers

Helpers for Yii2

116.6k2](/packages/yiier-yii2-helpers)

PHPackages © 2026

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