2017 © Pedro Peláez
 

cakephp-plugin cakephp-multivalidation-behavior

A CakePHP behavior that allows easy modifying of validation rules on the fly.

image

codaxis/cakephp-multivalidation-behavior

A CakePHP behavior that allows easy modifying of validation rules on the fly.

  • Tuesday, January 26, 2016
  • by codaxis
  • Repository
  • 2 Watchers
  • 6 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

CakePHP MultiValidation behavior

A CakePHP behavior that allows easy modifying of validation rules on the fly., (*1)

Compatible with Cake 2.4.7+, (*2)

Feel free to make any code/docs contributions or post any issues., (*3)

Build Status, (*4)

How to install

You can just copy the behavior file to your APP/Model/Behavior folder, (*5)

or, (*6)

You can also install the plugin as with every other plugin:, (*7)

  • Put the files in APP/Plugin/MultiValidation
  • In your bootstrap.php add CakePlugin::load('MultiValidation') or just CakePlugin::loadAll()

How to use

Enable the plugin in your target model:, (*8)

class User extends AppModel {

    public $actsAs = array(
        'MultiValidation.MultiValidation' => array(
            'types' => array(
                'enforceUsernameAndEmail' => array(
                    'username' => array(
                        'onlyAlpha' => array(
                            'rule' => 'alphaNumeric'
                        ),
                    ),
                    'email' =>
                        'validEmail' => array(
                            'rule' => 'email',
                            'required' => true
                        ),
                    )
                ),
                'enforcePassword' => array(
                    'password' => array(
                        'minCharsAllowed' => array(
                            'rule' => array('minLength', 8)
                        ),
                    ),
                ),
            )
        )
    )

    public $validate = array(
        'username' => array(
            'mustNotBeBlank' => array(
                'rule' => 'notEmpty'
            )
        ),
        'password' => array(
            'minCharsAllowed' => array(
                'rule' => array('minLength', 4)
            )
        ),
    );
}

Then in your model or controller you can do the following actions:, (*9)

    // Add new username and email validation:
    $User->addValidation('enforceUsernameAndEmail');
    // $User->loadedValidation() would return array('enforceUsernameAndEmail')

    // Reset to default state:
    $User->resetValidation();
    // $User->loadedValidation() would return array('_default')

    // Load and set only the password validation:
    $User->loadValidation('enforcePassword');
    // $User->loadedValidation() would return array('enforcePassword')

    // Add the other validation type also:
    $User->addValidation('enforceUsernameAndEmail');
    // $User->loadedValidation() would return array('enforcePassword', 'enforceUsernameAndEmail')

    // Reset again to default state:
    $User->resetValidation();
    // $User->loadedValidation() would return array('_default')

The Versions

26/01 2016

dev-master

9999999-dev https://github.com/Codaxis/cakephp-multivalidation

A CakePHP behavior that allows easy modifying of validation rules on the fly.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

cakephp validation multivalidation

24/04 2014

1.0

1.0.0.0 https://github.com/Codaxis/cakephp-multivalidation

A CakePHP behavior that allows easy modifying of validation rules on the fly.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

cakephp validation multivalidation