We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Phalcon model validation


I am using the StringLenght validation on a column "name", but in the database it's set as default NULL, but when I use the stringLength function, it requires the field to be filled no matter what. I can't leave it NULL and I dont use PresenceOf?

How can I return NULL, if name is not filled?



but perhaps you have to

if ($_POST['name'] === "") {
    $name = null;

What i am trying to do is:

$comment->userid = $userid;
$generate = new \Models\Statistics\Statistics();
$comment->guestid = $generate->uniqid();
$comment->name = $this->request->getPost('name');

The problem is, that I dont need to past a name to comment->name if userid exist. However, it says it still need to be filled. The default in database is NULL?


test when you add "allowEmpty" => true to your stringLength validator

It's can't be empty if i want it to be set.

I only need it to ask stringLenght when I use $robot->name But if i dont use that, then ignore the validation, becuase I dont need to set it

Hope you understand


nope sorry, i really dont get it. post few examples if you still need a solution

Just use allowEmpty :C