承接 xire28/redbean-validation 相关项目开发

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

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

xire28/redbean-validation

Composer 安装命令:

composer require xire28/redbean-validation

包简介

Php-activerecord validations for redbean

README 文档

README

Php-activerecord validations for redbean

Requirements

  • PHP >= 5.4.0

Documentation

Install

Using Composer

composer require xire28/redbean-validation

Example

<?php
require 'vendor/autoload.php';
require 'rb.php';

R::setup( 'mysql:host=localhost;dbname=redbean', 'root', '' );

class Model_User extends RedBean_SimpleModel
{
  use RedbeanValidation\ModelValidation;

  static $validates_length_of = [
    ['first_name', 'within' => [5, 20]],
    ['last_name', 'within' => [5, 20]]
  ];

  static $validates_uniqueness_of = [
    [['first_name', 'last_name'], 'message' => 'name already in use']
  ];

  public function validate(){
    if ($this->first_name == $this->last_name)
    {
        $this->errors->add('first_name', "can't be the same as last name");
        $this->errors->add('last_name', "can't be the same as first name");
    }
  }
}

$user = R::dispense('user');
$user->first_name = 'John';
$user->last_name = 'John';
if($user->is_valid()) 
{
  R::store($user);
}
else
{
  var_dump($user->errors());
}

Output

Note

  • A "John John" user exists in the database (created without using validations)
object(RedbeanValidation\Errors)[17]
  private 'model' => null
  private 'errors' => 
    array (size=3)
      'first_name' => 
        array (size=2)
          0 => string 'is too short (minimum is 10 characters)' (length=39)
          1 => string 'can't be the same as last name' (length=30)
      'last_name' => 
        array (size=2)
          0 => string 'is too short (minimum is 10 characters)' (length=39)
          1 => string 'can't be the same as first name' (length=31)
      'first_name_and_last_name' => 
        array (size=1)
          0 => string 'name already in use' (length=19)

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固