Kohana's validate validation Array

Source: Internet
Author: User
Tags kohana

Introduction: This is a detailed page of Kohana's validate check array. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 343574 'rolling = 'no'>

Because this class of the validation class array does not have relevant documents, make a note and be careful to forget it later.

ClassController_test
ExtendsController_smarty {

Public FunctionAction_index (){

$ _ Get =Array(

'A' => 'aaaaa ',

'B' =>''

);

$ Validate = validate ::Factory($ _ Get );

//@ Todo
Start here

// Display fields by TAG assignment

// Parameter: field, display name

$ Validate-> label ('A', 'A' attribute ');

$ Validate-> label ('B', 'B attribute ');

// All fields are used when the field is set to true.

// Verify the validity of a field through the callback function

// Parameter: field, callback function, additional parameter

$ Callbacks =Array(

Array($ This, 'A '),

);

$ Validate-> callbacks ('A', $ callbacks );

$ Validate-> callback ('A ',Array($ This, 'a1 '),Array('Pas1', 'pas2'); // function a ($ validate, $ field, $ Params)

$ Validate-> callback ('B ',Array($ This, 'B '),Array('Pas1'); // function A1 ($ validate, $ field, $ Params)

$ Rule =Array(

'Min _ length' =>Array(4 ),

'Max _ length' =>Array(32 ),

'Regex' =>Array('/^ [-\ PL \ PN _.] + $/UD '),

);

// Verify the validity of a field through rules

// The parameters of the rule function are transmitted in the form of an array list.

// Parameter: field, rule Array

$ Validate-> rules ('A', $ rule); // use the rule. The rule message is displayed in validate.

// Pass rule verification

// Parameter: field, rule function, parameter

$ Validate-> rule (True, 'Not _ empty ',Null); // Filter

// Filter

// Parameter: field, static method or function, additional parameter

$ Validate-> filter (True, 'Trim'); // Filter

// Static method or function: static function FA ($ value, $ Params) specifies that the field value is equal to the return value.

$ Validate-> filter ('A', get_class ($ This). ': Fa ',Array('Filterparams '));

If($ Validate-> check ()){

Print_r ($ validate ['a']);

Print_r ($ validate ['B']);

}Else{

// Retrieval Error

// Parameter: Message file name, whether to translate

$ MSG = $ validate-> errors ('A ');

Print_r ($ MSG );

$ This-> end ();

}

}

Public FunctionA1 ($ vaildate, $ filed, $ par ){

// Add Error

// Parameter: field in the message file, which is a one-dimensional array passed into the message file

$ Vaildate-> error ('A', 'invalid', $ par );//

}

Public FunctionA ($ vaildate, $ filed, $ par ){

}

Public FunctionB ($ vaildate, $ filed, $ par ){

}

Public static functionFa($ Value, $ Params ){

Return'123 ';

}

}

Configure the following array by calling the verification in the Orm, and call the check method.

Protected$ _ Rules =Array();

Protected$ _ Callbacks =Array();

Protected$ _ Filters =Array();

Protected$ _ Labels =Array();

Check failed: Check object can be obtained in attribute: Validate

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/343574.html pageno: 5.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.