Hello,
I try to create my own validation, But I have an error of provider because I do not know what to put.
//vendor/maitrepylos/Validation.php
//App/Model/Validation/ProjectValidation.php
-- I try to create my own validation, But I have an error of provider because I do not know what to put.
//vendor/maitrepylos/Validation.php
<?php
namespace Maitrepylos;
use Cake\Datasource\ConnectionManager;
class Validation extends \Cake\Validation\Validation {
public static function uniqueIdentifiant($check){
$pdo = ConnectionManager::get('default');
$sql = 'SELECT count(*) as compteur FROM catalogue WHERE t_identifiant = ?';
$r = $pdo->prepare($sql);
$r->execute([$check]);
$d = $r->fetch(\PDO::FETCH_OBJ);
if($d->compteur > 0){
return false;
}
return true;
}
}
//App/Model/Validation/ProjectValidation.php
<?phpThank you for your help
namespace App\Model\Validation;
use Cake\Datasource\ConnectionManager;
use Cake\Validation\Validator;
class ProjectValidation
{
public $validator = null;
public function __construct()
{
$this->validator = new Validator();
}
public function newFiche(){
$this->validator->requirePresence('t_titre', true)
->notEmpty('t_titre', 'Le nom de la fiche ne peut être absente')
->notEmpty('d_date_creation','La date ne peut être vide')
->add('d_date_creation',[
'checkDate'=>[
'rule'=>['date','dmy'],
'message' => 'La date doit-être au format d/m/Y'
]
])
->notEmpty('t_identifiant', 'L\'identifiant ne peut être vide')
->add('t_identifiant',[
'single' =>
[
'rule' => ['uniqueIdentifiant'],
'provider'=>'??????????????????????????', //I don't know
'message' => 'test unique'
]
]);
return $this->validator;
}
}
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment