承接 carono/yii2-validation-exception 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

License PHP Version

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-31