About

Breaking

Wednesday 24 May 2017

Data Validation

Data Validation

Data validation is an important part of any application, as it helps to make sure that the data in a Model conforms to the business rules of the application. For example, you might want to make sure that passwords are at least eight characters long, or ensure that usernames are unique. Defining validation rules makes form handling much, much easier.
There are many different aspects to the validation process. What we’ll cover in this section is the model side of things. Essentially: what happens when you call the save() method of your model. For more information about how to handle the displaying of validation errors, check out FormHelper.
The first step to data validation is creating the validation rules in the Model. To do that, use the Model::validate array in the Model definition, for example:

डेटा मान्य
 
डाटा सत्यापन किसी भी आवेदन का एक महत्वपूर्ण हिस्सा है, क्योंकि यह सुनिश्चित करने में मदद करता है कि मॉडल में डेटा आवेदन के व्यावसायिक नियमों के अनुरूप है। उदाहरण के लिए, आप यह सुनिश्चित कर सकते हैं कि पासवर्ड कम से कम आठ अक्षर लंबा हों, या यह सुनिश्चित करें कि उपयोगकर्ता नाम अद्वितीय हैं सत्यापन नियम को परिभाषित करना फॉर्म बहुत ही सरल, बहुत आसान है।

सत्यापन प्रक्रिया के लिए कई अलग-अलग पहलू हैं इस खंड में हम जो कुछ भी शामिल करेंगे वह चीज़ों का मॉडल पक्ष है। मूलतः: जब आप अपने मॉडल की सहेज () विधि को कॉल करते हैं तो क्या होता है सत्यापन त्रुटियों को प्रदर्शित करने के तरीके के बारे में अधिक जानकारी के लिए, फॉर्महाल्पर देखें

डेटा सत्यापन का पहला चरण मॉडल में सत्यापन नियम बना रहा है। ऐसा करने के लिए, आदर्श परिभाषा में मॉडल :: मान्य करें सरणी का उपयोग करें, उदाहरण के लिए:

class User extends AppModel {
    public $validate = array();
}

 

In the example above, the $validate array is added to the User Model, but the array contains no validation rules. Assuming that the users table has login, password, email and born fields, the example below shows some simple validation rules that apply to those fields:

ऊपर दिए गए उदाहरण में, $ मान्य एरे उपयोगकर्ता मॉडल में जोड़ा जाता है, लेकिन सरणी में कोई सत्यापन नियम नहीं है। यह मानते हुए कि उपयोगकर्ता तालिका में लॉगिन, पासवर्ड, ईमेल और जन्म के खेतों हैं, नीचे दिए गए उदाहरण उन फ़ील्ड पर लागू होने वाले कुछ सरल सत्यापन नियम दिखाते हैं:

<?php
class Student extends AppModel{
public $validate = array(
                'name'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                'phone'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                'address'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                'addmission_date'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                // 'class_id'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                );


Simple Rules

As the name suggests, this is the simplest way to define a validation rule. The general syntax for defining rules this way is:

सरल नियम
 
जैसा कि नाम से पता चलता है, यह एक सत्यापन नियम को परिभाषित करने का सबसे सरल तरीका है। इस तरह से नियमों को परिभाषित करने के लिए सामान्य वाक्यविन्यास है:
public $validate = array('fieldName' => 'ruleName');





Example Code:

<?php
class Student extends AppModel{
public $validate = array(
                'name'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                'phone'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                'address'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                'addmission_date'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                // 'class_id'=>array('notEmpty'=>array('rule'=>array('notEmpty'),),),
                );
public $belongsTo = array(
 'Classroom'=>array('className'=>'Classroom','foreignKey'=>'classrooms_id','field'=>array('id','name'),'type'=>'left'),
 );

}
 



           RESULT

 अगर  आप  का  CODE  सही  होगा  तो  आप  को  कॉलम  के  आगे  STAR  जैस  सिमबोल  दिखे  ग  
 If your code is right then you will see a symbol like STAR next to the column



No comments:

Post a Comment