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

Disable Auto Validation

Hello. if the null flag in table definition be No and we send the empty value to the this table model, the app will say this field is required ( Automatic Validation ) Is there any way to prevent this ?

in php.ini

; Enables/Disables automatic NOT NULL validation
phalcon.orm.not_null_validations = On

or:

\Phalcon\Mvc\Model::setup(array(    
    'notNullValidations' => false
));


15.4k
edited Mar '14

Thank you, i have another question, how i can show validation error messages in views in the multiple apps ? i used flash messages and redirect method of response object but its not working ...

here is my codes : <?php // here is validation falied section else { foreach($valid as $message) { $this->flash->error((string)$message); }

        return $this->response->redirect("people_zone/people/new-people.html");
    }

    $this->view->disable();

?>

and in my view page:

{{content()}}

edited Mar '14

for $this->response->redirect() - you have to register and use flashSession component in your DI - it is handle by two request, so you have to use session

for $this->dispatcher->forward() - you have to register and use flash component in your DI - it is handle by the same request

$di->set(
    'flashSession',
    function () {
        return new Phalcon\Flash\Session(array(
            'error' => 'alert alert-dismissable alert-danger',
            'success' => 'alert alert-dismissable alert-success',
            'notice' => 'alert alert-dismissable alert-info',
        ));
    }
);

$di->set(
    'flash',
    function () {
        return new Phalcon\Flash\Direct(array(
            'error' => 'alert alert-dismissable alert-danger',
            'success' => 'alert alert-dismissable alert-success',
            'notice' => 'alert alert-dismissable alert-info',
        ));
    }
);


15.4k
edited Mar '14

@karol : It's okay now, Thank you, bu can you expalin what is diffrence between dispatcher->forward and response->redirect ?

response->redirect() is like header("Location: https://url"), so when http is stateless you have to use session to store messages so you have to use flashSession.

dispatcher->forward() doesn't reload page this is the same request so you don't need to store messages in session, so you can use flash service