Validation for Birth date >49 at Model level or xxx.ctp or even Controller?

In Model/table we have a membres.php with that statement:
$validator
->date(‘date_de_naissance’)
->requirePresence(‘date_de_naissance’, ‘create’, ‘Une date de naissance est requise.’)
->notEmpty(‘date_de_naissance’, true, ‘La date de naissance ne peut pas être vide.’);
we want to add extra validation for date_de_naissance > 49.
And at entry level (template): filename.ctp:

<?= $this->Form->control('date_de_naissance', ['label' => 'Date de naissance', 'required' => true, 'monthNames' => $mois, 'minYear' => 1900, 'maxYear' => date('Y')]) ?>

Please help
New in CakePHP but enthusiastic

if i understand correctly you only give year to validate so maybe something like this

use Cake\I18n\Date;

...

$atLeast49 = (new Date())->subYears(49)->year;

$validator
       ->lessThan('date_de_naissance', $atLeast49, 'Too young.');

Hello Graziel,
thanks for quick reply;
In which file do I insert this statement:```
$atLeast49 = (new Date())->subYears(49)->year;

I inserted " $validator... in myproject\src\Model\Table\MembresTable.php

Can I give you access to some files .ctp, .php ??
Thanks for your help

Yes it should go in your table implementation, along with any other validation that’s there.

Hello Graziel,
I do not know where to put or set the following variable:
$atLeast49 = (new Date())->subYears(49)->year;

I have a MembresController.php and a ajouter.ctp so a MembresTable.php
Here is the link: https://1drv.ms/u/s!AtxUdY_g_iSIlAvcb6aIp0AMcBmk?e=3Zl5M9
Thanks for helping

the code should go to

public function validationDefault(Validator $validator)
{
   ...
}

inside MembresTable

This validation still not working, maybe I did not send enough info:
*/
class MembresTable extends Table {

/**
 * Méthode initialize.
 * @param array $config La configuration de la table.
 * @return void
 */
public function initialize(array $config) {
	parent::initialize($config);
	$this->addBehavior('Timestamp');
	$this->belongsTo('Types', ['joinType' => 'INNER']);
	$this->belongsTo('Utilisateurs', ['foreignKey' => 'ajoute_par_utilisateur_id', 'joinType' => 'INNER']);
	$this->belongsTo('Utilisateurs', ['foreignKey' => 'modifie_par_utilisateur_id', 'joinType' => 'INNER']);
	$this->hasMany('Inscriptions');
	$this->hasMany('ListesAttente');
	$this->belongsToMany('Activites', ['joinTable' => 'inscriptions']);
}

public function checkOver50($check) {
	$this->$bday = strtotime($check['date_de_naissance']);
		if (time() < strtotime('-49 years', $bday)) return false;
	return true;

here is what I find in MembresTable.php
$validator
->date(‘date_de_naissance’)
->requirePresence(‘date_de_naissance’, ‘create’, ‘Une date de naissance est requise.’)
->notEmpty(‘date_de_naissance’, true, ‘La date de naissance ne peut pas être vide.’)
->add(‘deb’,‘age’), [
‘rule’ => [checkOver50],
‘message’ => ‘Un member ou non-membre doit avoir 50 ans ou plus’
]);

Here is the link to these files:

https://1drv.ms/u/s!AtxUdY_g_iSIlAvcb6aIp0AMcBmk?e=3Zl5M9