sorokinmedia / yii2-custom-fields
Custom fields(json) component for Yii2
Installs: 15
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 0
Open Issues: 0
Type:yii2-extension
pkg:composer/sorokinmedia/yii2-custom-fields
Requires
- sorokinmedia/yii2-ar-relations: *
- sorokinmedia/yii2-helpers: dev-master
- yiisoft/yii2: >=2.0.6
Requires (Dev)
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2025-10-23 03:43:03 UTC
README
Sorokin.Media repository
Компонент для работы с custom_fields внутри любой AR модели. Работа с json-полем в БД.
Описание модели CustomFieldModel (кастомное поле)
атрибуты:
- id- id, уникальный итератор -- integer
- name- название поля -- string(255)
- value- значение поля -- string
- number- порядковый номер для Drag'n'Drop -- integer
Общий принцип работы
В атрибут AR модели пишем массив объектов CustomFieldModel, в json формате. Вся работа с этим полем организована в CustomFieldHelper.
Описание хелпера CustomFieldHelper
Содержит ряд вспомогательных методов для работы с атрибутом custom_fields. Все методы в хелпере статические.
- public static function getMaxId(array $custom_fields = null) : int- получает текущий максимальный- IDв массиве полей. Если атрибут- custom_fieldsпуст(- null), вернет- 0.
- public static function addCustomFields(array $custom_fields_array, array $custom_fields = null) : array- добавляет массив кастомных полей в атрибут- custom_fields. Автоматически проставляет- idвнутри моделей- CustomFieldModel. Первый параметр - массив полей, которые нужно добавить. Вторым параметров принимает уже существующие поля, к которым нужно добавить поля из первого параметра.
- public static function updateCustomField(array $custom_field_array, array $custom_fields) : array- обновляет поле внутри массива полей- custom_fields. Ищет по- idэлемента и заменяет. Первый параметр - новое поле, второй параметр - уже существующие поля.
- public static function deleteCustomField(int $id, array $custom_fields) : array- удаляет модель- CustomFieldModelвнутри массива полей- custom_fields. Ищет по- id. Первый параметр -- idэлемента, который нужно удалить, второй параметр - уже существующие поля.