carono/yii2-validation-exception
最新稳定版本:1.0.0
Composer 安装命令:
composer require carono/yii2-validation-exception
包简介
An exception for the model in case of erroneous validation
关键字:
README 文档
README
A simple Yii2 extension that provides a specialized exception class for handling model validation errors.
Features
- Throws an exception with the first validation error message when model validation fails
- Provides direct access to the failed model instance
- Easy integration with Yii2 applications
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require carono/yii2-validation-exception
or add
"carono/yii2-validation-exception": "*"
to the require section of your composer.json file.
Usage
use carono\yii2\exceptions\ValidationException; use yii\base\Model; $model = new Model(); $model->addError('attribute', 'Validation error message'); // Throw exception with the first validation error throw new ValidationException($model); // Or use it in a try-catch block try { if (!$model->validate()) { throw new ValidationException($model); } // Continue with valid model } catch (ValidationException $e) { // Access the error message echo $e->getMessage(); // "Validation error message" // Access the model instance $failedModel = $e->model; }
License
The MIT License (MIT). Please see License File for more information.
Author
Alexander Kasyanov - carono.ru - info@carono.ru
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-31