filmov
tv
Learn CakePHP v3.5 Tutorial in HINDI for beginners (Part 24) Data Validation in CakePHP(Model)

Показать описание
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:
Important Videos, you should watch:
About CakePHP Installation
==================
After installation check your composer installation via command: composer into terminal
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 :
===============
Also you can learn Wordpress Custom
===============
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 :)
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:
Important Videos, you should watch:
About CakePHP Installation
==================
After installation check your composer installation via command: composer into terminal
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 :
===============
Also you can learn Wordpress Custom
===============
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 :)
Комментарии