jorge/custom-cakephp3

CakePHP 3 Custom

Installs: 2 476

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1

Open Issues: 0

Type:cakephp-plugin

v1.0 2015-06-08 21:43 UTC

This package is auto-updated.

Last update: 2024-11-28 14:57:05 UTC


README

Instalação

<?php
    Plugin::load("JCustomCakephp3");

Como usar

1. Ajuste dos campos de data para o formato SQL americano.

Add no Model:

<?php

    class PostsTable extends Table
    {
        public function initialize($config = [])
        {
            $this->addBehavior("JCustomCakephp3.ConvertDate");
        }
    }

ou

<?php

    class PostsTable extends Table
    {
        public function initialize($config = [])
        {
            $this->addBehavior("JCustomCakephp3.ConvertDate", ['fild_name1', 'fild_name2']);
        }
    }

2. Validação de dados brasileiros.

Add no Model no método validationDefault():

<?php

public function validationDefault(Validator $validator)
{
    $validator
        ->provider('custom', new \JCustomCakephp3\Validation\CustomProvider)
        ->add('birth', 'valid', ['rule' => 'dateBR', 'provider' => 'custom'])
        ->requirePresence('birth', 'create')
        ->notEmpty('birth');
}

Rules:

  • dateBR
  • datetimeBR
  • cnpj
  • cpf
  • cep
  • phone
  • cellphone