In this video we have discussed about Data validation in cakePHP,Validation rules in cakePHP
By Writting our Validation we can specify these either in Controller or in Model.
Here, we will see rules in Model.
Steps to do:
=============
Just use this in Model:
use Cake\Validation\Validator;
Here is the complete code of Model:
===============
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class TestsTable extends Table{
public function validationDefault(Validator $validator){
//rules
$validator-requirePresence("email","create","Email Should be needed")
-add("email",[
"unique"=[
"rule"="validateUnique",
"provider"="table",
"message"="Email should be unique"
]
])
-requirePresence("password","create","Password is needed")
-requirePresence("confirm_password","create","Confirm Password is needed")
-add("confirm_password",[
"password_mismatch"=[
"rule"=["compareWith","password"],
"message"="Password didn't match"
]
])
;
return $validator;
}
}
How to use in Controller
====================
$this-loadModel("Tests");
$validation = $this-Tests-newEntity($req_data); // $this-request-data
$validationErrors = $validation-errors();
if(!empty($validationErrors)){
//errors
print_r($validationErrors);
}else{
// passed
echo "Successfully Passed";
}
If any errors comes then "$validation" stores all errors.
To read the documentation of all these best way to read from its File:
file: /vendor/cakephp/cakephp/src/Validation/Validator.php
Important Videos, you should watch:
1. Folder structure in cakePHP: • Learn CakePHP v3.5 Tutorial in HINDI for b...
2. CakePHP Installation Guide: • Learn CakePHP v3.5 Tutorial in HINDI for b...
3. CakePHP Application Flow Mechanism: • Learn CakePHP v3.5 Tutorial in HINDI for b...
4. Controller in CakePHP: • Learn CakePHP v3.5 Tutorial in HINDI for b...
5. Views in CakePHP: • Learn CakePHP v3.5 Tutorial in HINDI for b...
6. Flah Helper: • Learn CakePHP v3.5 Tutorial in HINDI for b...
7. Custom Helper: • Learn CakePHP v3.5 Tutorial in HINDI for b...
8. Recommended(Part 19): Table Objects(Select, Insert): • Learn CakePHP v3.5 Tutorial in HINDI for b...
9. Recommended(Part 23): Validation using Controller ( • Learn CakePHP v3.5 Tutorial in HINDI for b... )
About CakePHP Installation
==================
1. Install composer: https://getcomposer.org
After installation check your composer installation via command: composer into terminal
2. Copy the Project Creating Command for cakePHP (https://book.cakephp.org/3.0/en/insta...)
command: php composer.phar create-project --prefer-dist cakephp/app my_app_name
before using this command make sure about your composer path
3. Paste the above command into command prompt/ terminal and hit inter.
4. Thats it Done :)
SOCIAL :
===============
Subscribe : / @onlinewebtutor
FACEBOOK : / onlinewebtutorhub
TWITTER: / owthub
BLOG: https://onlinewebtutorhub.blogspot.in/
Also you can learn Wordpress Custom
===============
Wordpress Theme Development: https://goo.gl/MZ8maF
Wordpress Widget Development: https://goo.gl/Dc2htn
Wordpress Plugin Development: https://goo.gl/BA7dYG
Wordpress Theme Options Development: https://goo.gl/Vjv3Ub
Learn backbone.js here! : https://goo.gl/Qd2Pcs
Tags
===============
learn cakephp 3.5,
cakephp tutorial,
cakephp tutorial in hindi,
cakephp tutorial for beginners step by step,
cakephp 3,
cakephp 3 tutorial for beginners step by step,
cakephp 3 tutorial,
cakephp 3.5 tutorial,
cakephp tutorial for beginners step by step in hindi,
cakephp tutorial step by step,
cakephp tutorial for beginners,
learn cakephp in hindi,
learn cakephp step by step,
learn cakephp for beginner,
learn cakephp 3,
learn cakephp,
online web tutor,
profotech solutions,
Thanks
Online Web Tutor
Keep learning and Sharing :)
Информация по комментариям в разработке