sw-fw-less
  • sw-fw-less
  • get started
    • Installation
    • Directory
    • Config
    • Quick Start
  • MVC
    • Router
    • Middleware
    • Request
    • Param Validator
    • Model
    • Response
  • Database
    • MySQL
    • Redis
    • Elasticsearch
  • Storage
    • General
    • File
    • Qiniu
    • Alioss
  • OTHER
    • Pagination
    • Helper
    • Error Handler
    • AMQP-0-9-1
    • Events
  • Deployment
    • Nginx
    • Docker
  • APPENDIX
    • Development Rules
Powered by GitBook
On this page
  • Cake Validation
  • Phalcon Validation(Recommended)

Was this helpful?

  1. MVC

Param Validator

PreviousRequestNextModel

Last updated 6 years ago

Was this helpful?

Cake Validation

$errors = (new \Cake\Validation\Validator())->requirePresence('key')
    ->lengthBetween('key', [1, 10])
    ->add('key', 'string', [
        'rule' => [\App\components\Validator::class, 'string'],
        'message' => 'key is not a string'
    ])->errors($params);

For detailed usage of cake validation, please see .

Phalcon Validation(Recommended)

Before using this validation, please install phalcon extension.

$messages = (new Validation())->add('key', new Validation\Validator\PresenceOf(['message' => 'key is required']))
    ->add('key', new Validation\Validator\StringLength(['min' => 1, 'max' => 10, 'message' => 'key is not between 1 t0 10']))
    ->add('key', new Validation\Validator\Callback([
        'callback' => function($data) {
            return \App\components\Validator::string($data['key'], $data);
        },
        'message' => 'key is not a string',
    ]))->validate($params);
$errors = [];
foreach ($messages as $message) {
    $errors[] = $message->getMessage();
}

For detailed usage of phalcon validation, please see .

document
document