2017 © Pedro Peláez
 

cakephp-plugin patternable-validator

PatternableValidator plugin for CakePHP 3

image

k1low/patternable-validator

PatternableValidator plugin for CakePHP 3

  • Thursday, April 7, 2016
  • by k1LoW
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,913 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

PatternableValidator plugin for CakePHP 3

Installation

You can install this plugin into your CakePHP application using composer., (*1)

The recommended way to install composer packages is:, (*2)

composer require k1low/patternable-validator

Usage

Before

<?php
namespace App\Model\Table;

class UsersTable extends AppTable
{
    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('username')
            ->add('username', 'minLength4', [
                'rule' => ['minLength', 4],
                'message' => __('Validation Error: minLength4'),
            ])
            ->add('username', 'maxLength10', [
                'rule' => ['maxLength', 10],
                'message' => __('Validation Error: maxLength10'),
            ]);

        $validator
            ->allowEmpty('password');
    }
}

After

<?php
namespace App\Model\Table;

class UsersTable extends AppTable
{
    public function validationDefault(Validator $validator)
    {
        $validator
            ->addPattern('id', ['integer', 'allowEmptyWhenCreate']);

        $validator
            ->addPattern('username', ['allowEmpty', 'username_length']);

        $validator
            ->appPattern('password', ['allowEmpty']);
    }
}

AppTable settings:, (*3)

<?php
namespace App\Model\Table;

class AppTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);
        $this->_validatorClass = '\PatternedValidator\Validation\Validator';
        \PatternedValidator\Validation\Validator::$validationPatterns = [
            'username_length' => [
                'minLength4' => [
                    'rule' => ['minLength', 4],
                    'message' => __('Validation Error: minLength4'),
                ],
                'maxLength10' => [
                    'rule' => ['maxLength', 10],
                    'message' => __('Validation Error: maxLength10'),
                ]
            ],
        ];
    }
}

for CakePHP 2

see cakeplus/ValidationPatternsBehavior.php, (*4)

The Versions

07/04 2016

dev-master

9999999-dev

PatternableValidator plugin for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

validation

01/04 2016

v1.2.0

1.2.0.0

PatternableValidator plugin for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

validation

01/04 2016

v1.1.1

1.1.1.0

PatternableValidator plugin for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

validation

23/03 2016

v1.1.0

1.1.0.0

PatternableValidator plugin for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

validation

22/03 2016

v1.0.0

1.0.0.0

PatternableValidator plugin for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

validation