Tuesday, September 1, 2015

Re: Compare 2 date in cake3

'custom',['rule' =>  [$this, 'checkDate']]

this doesn't seems to be a correct syntax... Why don't you use one of the proposed solution ?

Le 1 sept. 2015 10:46, "lorenzoshake" <ferri.lorenzo@gmail.com> a écrit :


Il giorno martedì 1 settembre 2015 10:44:40 UTC+2, lorenzoshake ha scritto:


Il giorno lunedì 31 agosto 2015 18:34:37 UTC+2, Anthony GRASSIOT ha scritto:

Maybe something like:

                'compare' => [
                    'rule' => function ($value, $context) {
                        return $value->gte($context['data']['start_date']);
                    }


now the check was executed:
    public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create')
            ->add('social_user_id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('social_user_id')
            ->allowEmpty('name')
            ->allowEmpty('address')
            ->allowEmpty('city')
            ->add('lat', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('lat')
            ->add('lng', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('lng')
            ->add('start_date', 'valid', ['rule' => 'date'])
            ->add('end_date', 
                'custom',['rule' =>  [$this, 'checkDate']]
            );
            
        return $validator;
    } 
  but the record was always saved ( checkDate return always false for test)
 

--
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.

--
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: