PHPackages                             denisok94/yii-helper - 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. denisok94/yii-helper

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

denisok94/yii-helper
====================

\--

0.0.4(1y ago)019BSD-3-ClausePHP

Since Jun 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Denisok94/yii-helper)[ Packagist](https://packagist.org/packages/denisok94/yii-helper)[ RSS](/packages/denisok94-yii-helper/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

 Yii2 Helper Class
===================

[](#-yii2-helper-class-)

Installation
============

[](#installation)

Run:

```
composer require --prefer-dist denisok94/yii-helper
# or
php composer.phar require --prefer-dist denisok94/yii-helper
```

or add to the `require` section of your `composer.json` file:

```
"denisok94/yii-helper": "*"
```

```
composer update
# or
php composer.phar update
```

Use
===

[](#use)

- [StatusController](#StatusController)
- [ConsoleController](#ConsoleController)
- [Helper](#Helper)

**StatusController**
====================

[](#statuscontroller)

For communication in the json format.

MethodParametersdefault codeDescriptionsend$data200custom responsessendSuccess$data200Report SuccesssendResponse$data, $message, $status, $code200custom responsessendError$message, $status, $code400Report an errorsendBadRequest$message400sendUnauthorized$message401sendForbidden$message403sendNotFound$message404sendInternalServerError$message500getPost$name--Получить параметр из сообщенияsuccess$data--outdatederror$error, $text, $data--outdated```
namespace app\controllers;
use \denisok94\helper\yii2\StatusController;

class MyController extends StatusController
{
    // code
}
```

```
// получить все данные
$message = $this->post; // array
// получить параметр из данных
$phone = $this->getPost('phone'); // phone or null
```

Report Success

```
// Сообщить об успешной обработки
return $this->sendSuccess(); // http status code 200
// ['code' => '200', 'status' => 'OK', 'data' => []];
// Вернуть результат работы
return $this->sendSuccess($data);  // http status code 200
// ['code' => '200', 'status' => 'OK', 'data' => $data];
```

Report an error

```
return $this->sendError(); // http status code 400
// ['code' => '400', 'status' => 'FAIL', 'message' => 'Error', 'data' => []]
return $this->sendError($message); // http status code 400
// ['code' => '400', 'status' => 'FAIL', 'message' => $message, 'data' => []]
return $this->sendError($message, $data); // http status code 400
// ['code' => '400', 'status' => 'FAIL', 'message' => $message, 'data' => $data]
return $this->sendError($message, $data, 401); // http status code 401
// ['code' => '401', ...]

// return ['code', 'status', 'message'];
return $this->sendBadRequest(); // http status code 400
return $this->sendUnauthorized(); // http status code 401
return $this->sendForbidden(); // http status code 403
return $this->sendNotFound(); // http status code 404
return $this->sendInternalServerError(); // http status code 500

if (!$this->post) {
    return $this->sendBadRequest("Request is null"); // http status code 400
    // ['code' => '400', 'status' => 'FAIL', 'message' => 'Request is null']
}

try {
    //code...
} catch (\Exception $e) {
    return $this->sendInternalServerError($e->getMessage()); // http status code 500
    // ['code' => '500', 'status' => 'FAIL', 'message' => '...']
}
```

Custom response format

```
return $this->send([...]); // http status code 200
// [...];
return $this->send(['code' => 204]); // http status code 204
// ['code' => '204'];
return $this->send(['code' => 201, 'data' => $data]); // http status code 201
// ['code' => '201', 'data' => $data];

return $this->sendResponse($data); // http status code 200
// ['code' => '200', 'status' => 'OK', 'message' => '', 'data' => $data]
return $this->sendResponse($data, $message); // http status code 200
// ['code' => '200', 'status' => 'OK', 'message' => $message, 'data' => $data]
return $this->sendResponse($data, $message, $status, 999); // http status code 999
// ['code' => '999', 'status' => $status, 'message' => $message, 'data' => $data]
```

**ConsoleController**
=====================

[](#consolecontroller)

```
namespace app\commands;
use \denisok94\helper\yii2\ConsoleController;

class MyController extends ConsoleController
{
    // code
}
```

Вызвать `action` консольного контроллера:

```
use \denisok94\helper\yii2\Helper as H;
H::exec('controller/action', [params]);
```

> Консольный контроллер, не подразумевает ответ. Вся выводящая информация (echo, print и тд) будет записана в лог файл. При вызове через `H::exec()`, по умолчанию логи находятся в `/runtime/logs/consoleOut.XXX.log` (можно переопределить)

Получить переданные параметры

```
$init = $this->params;
```

Пример:

```
namespace app\commands;
use \denisok94\helper\yii2\ConsoleController;

class MyController extends ConsoleController
{
	public function actionTest()
	{
		$init = $this->params; // ['test' => 'test1']
		$test = $this->params['test']; // 'test1'
	}
}
//
use \denisok94\helper\yii2\Helper as H;
H::exec('my/test', ['test' => 'test1']);
```

**Helper**
==========

[](#helper)

```
use \denisok94\helper\yii2\Helper as H;
H::methodName($arg);
```

`yii2\Helper` наследует все от [Helpers](https://github.com/Denisok94/helper)

MethodDescriptionexecВыполнить консольную командуlogЗаписать данные в лог файл. Файлы хранятся в `runtime/logs/`setCacheЗапомнить массив в кэшgetCacheВзять массив из кэшаdeleteCacheУдалить кэшclearCache---

> `setCache`/`getCache`. В кэш можно сохранить результат запроса из бд, который часто запрашивается, например для фильтра. К тому же, этот фильтр, может быть, использоваться несколько раз на странице или сама страница с ним, может, многократно обновляться/перезагружаться.

```
namespace app\components;
use app\components\H;

class Filter
{
    //.....
    /**
     * @return array
     */
    public static function getTypes()
    {
        $types = H::getCache('types'); // dir: app/cache/types.json
        if ($types) {
            return $types;
        } else {
            $types = \app\models\Types::find()
                ->select(['id', 'name'])->all();
            $array = [];
            foreach ($types as $key => $value) {
                $array[$value->id] = ucfirst($value->name);
            }
            H::setCache('types', $array);
            return $array;
        }
    }
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

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.

###  Release Activity

Cadence

Every ~256 days

Total

4

Last Release

662d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/59793012?v=4)[Денис](/maintainers/Denisok94)[@Denisok94](https://github.com/Denisok94)

---

Top Contributors

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

---

Tags

yii2-extensionyii2-extension

### Embed Badge

![Health badge](/badges/denisok94-yii-helper/health.svg)

```
[![Health](https://phpackages.com/badges/denisok94-yii-helper/health.svg)](https://phpackages.com/packages/denisok94-yii-helper)
```

###  Alternatives

[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k47](/packages/skeeks-cms)[devanych/yii2-cart

Shopping cart for Yii2

2011.2k](/packages/devanych-yii2-cart)[yii2-extensions/franken-php

Supercharge your Yii2 applications with FrankenPHP blazing-fast HTTP server.

212.6k](/packages/yii2-extensions-franken-php)

PHPackages © 2026

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