public function validate() { if (empty($this->title)) { $this->setError('Title is required'); } return parent::validate(); }
public function validate() { $this->email = trim(strtolower($this->email)); // if you want, use $this->validateWith( $validator ) here if (empty($this->email)) { $this->setError('Email is required'); } if (empty($this->password)) { $this->setError('Password is required'); } // is the email unique? // this would be a great case for $this->validateWith( $validator ); -- using a Uniqueness Validator if (!empty($this->email) && ($existing = $this->emailExists($this->email))) { if (empty($this->id) || $this->id != $existing->id) { $this->setError('This email is already registered'); } } if (!empty($this->username)) { $this->username = static::usernameFromString($this->username); } if (empty($this->username)) { $this->username = $this->generateUsername(); } // is the username unique? // this would be a great case for $this->validateWith( $validator ); -- using a Uniqueness Validator if (!empty($this->username) && ($existing = $this->usernameExists($this->username))) { if (empty($this->id) || $this->id != $existing->id) { $this->setError('This username is taken'); } } return parent::validate(); }