We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How work the method prepareSave?

Hello good day. I need to add validations in my model. How will the new function work?

edited May '16

Just read the docs next time. For model validation you should use validation method - https://docs.phalcon.io/pl/latest/reference/models.html#validating-data-integrity.

It will be fired on save method(create/update).

Keep in mind that in 2.1.x validation will change a bit.

https://blog.phalcon.io/post/phalcon-2-1-beta-released



81.2k
edited May '16

Hi. I already updated. And add the following lines

use Phalcon\Validation;
use Phalcon\Mvc\Model\Validator\Email as EmailValidator;
use Phalcon\Mvc\Model\Validator\Uniqueness as UniquenessValidator;

public function validation()
{
    $this->validate(
        new UniquenessValidator(
            [
                'field'   => 'CONT_CEDULA',
                'message' => 'Sorry, That username is already taken',
            ]
        )
    );

    if ($this->validationHasFailed() == true) {
        return false;
    }
}

But he stays on a white screen does not work

This mean you have exception, just check logs...



81.2k

I did not know there were logs How do I check the logs ?. I reviewed the variables in the web browser.

I mean PHP LOGS, white page = means exception, it's not related to phalcon itself, it's related to php, why you are starting working with framework without any knowledge about php ?