PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 9, 2022

[FIXED] CakePHP 3.X: Difference buildSchema X buildValidator

 March 09, 2022     cakephp, cakephp-3.0, php, validation     No comments   

Issue

I'm learning CakePHP 3.X version and I'm really confused about Form validation.
In the documentation (http://book.cakephp.org/3.0/en/core-libraries/form.html) is saying that you need to create a class to validate your form and you have two methods to validate the data.

First method:

protected function _buildSchema(Schema $schema)
{
    return $schema;
}  

Second method:

protected function _buildValidator(Validator $validator)
{
    return $validator;
}  

What is the really difference between them?
In the documentation example is saying this:

_buildSchema is used to define the schema data that is used by FormHelper to create an HTML form. You can define field type, length, and precision.

_buildValidator Gets a Cake\Validation\Validator instance that you can attach validators to.

I'm confused because if you look at the examples in the documentation you gonna see that he's validating the input length and things like that in the second method, but in the description of the first method he's saying that you can do that too?

Is it possible to explain to me the really differece between them and show to me an example?

Thanks!


Solution

Database Schema

A database schema of a database system is its structure described in a formal language supported by the database management system (DBMS). The term "schema" refers to the organization of data as a blueprint of how the database is constructed.

The schema describes your data structure, your table layout. A blue print.

Data Validation

In computer science, data validation is the process of ensuring that a program operates on clean, correct and useful data. It uses routines, often called "validation rules" "validation constraints" or "check routines", that check for correctness, meaningfulness, and security of data that are input to the system. The rules may be implemented through the automated facilities of a data dictionary, or by the inclusion of explicit application program validation logic.

Validation is the process of checking the data you put into the database, into the schema that describes the structure for your data.

Conclusion

You need to describe your schema first. The data you put into it through the form is validated.

Also the documentation is pretty clear on that as well, I think you just misunderstood it: You can define field type, length, and precision. Defining something is not validating something. :)



Answered By - floriank
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing