M
M
Mikha Pankratov2015-12-08 23:09:37
Yii
Mikha Pankratov, 2015-12-08 23:09:37

How to write your own yii2 rules?

Hello,
I wrote my rules - but for some reason it does not work out.

public function rules() {
    return [
                        ['dob', 'validateBithday', 'skipOnEmpty' => false, 'skipOnError' => false],
    ];
  }

public function validateBithday($attribute, $params)
        {
            if(date('Y', strtotime($attribute)) > data('Y')-18){
                return $this->addError($attribute, 'You should be more years.');
            }
        }

in the date dob enter '2015-December-08'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikha Pankratov, 2015-12-09
@frmax

public function validateBithday($attribute, $params)
        {
            if(<b>date('Y', strtotime($this->dob)) > date('Y')-18)</b>{
                return $this->addError($attribute, 'You should be more years.');
            }
        }

The right decision!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question