UrlValidator in controllers ?

Hi,

I'm quite new with Phalcon and i'm trying to validate some datas from a form and I slowly understand how it exactly works. Anyway, I did something very similar to your documentation example about the Validation class ...

$validation = new Phalcon\Validation();

$validation->add('name', new PresenceOf(array(
    'message' => 'The name is required'
)));

$validation->add('email', new PresenceOf(array(
    'message' => 'The e-mail is required'
)));

$validation->add('email', new Email(array(
    'message' => 'The e-mail is not valid'
)));

Everything is ok until I try to validate an URL ; first I was thinking you didn't made an object to check URLs syntax, I fell on this ...

use Phalcon\Mvc\Model\Validator\Url as UrlValidator;

class Posts extends Phalcon\Mvc\Model
{

  public function validation()
  {
      $this->validate(new UrlValidator(array(
          'field' => 'source_url'
      )));
      if ($this->validationHasFailed() == true) {
          return false;
      }
  }

}

So there's a UrlValidator object which is made for what I exactly wanted to do, but is only available from my "models" (originally) ... And now I'm asking myself what are the exact difference between the Validator used in the models and the Validation in the controller, and more important, why some functionality which are in one, aren't in the other one ...

What is the aim ? Is it possible to couple the two of them ?

Thanks ;) maybe these are some dumb questions but I didn't catch anything about this ...

This is a complicated answer. I hope to see you back in IRC so I can help you there :)

As we said on IRC,

It seems there's no logical reason urlValidator wasn't cloned in the controllers validations. About the difference between the two classes, one is linked with the database entries - which is quite powerful - the other one can control any data and don't do much more ; that's why there are two different validations system.

Hi! How do you solve the problem?