Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How i can validate Orm object?
  • I have a Orm model that contains _properties fields and validation rules, i know that i can call valid function for true/false result or valid function will be called in save function, but is it possible to get validation object of that orm object?
    like crud models, ex.

    $validation = Model_Mymodel::validation();

    if( $validation->run())...


    other question is that, is it possible to get errors on valid() functions call?
  • If you use the validation observer, it will throw a ValidationFailed exception if the validation fails.

    The exception object has a get_fieldset() method which you can use to retrieve the fieldset that was generated for the model object.

    A fieldset object has a validation() method which returns the associated validation object. You can call the error() method to retrieve all validation error objects.
  • in this forum post, (last reply) has a simple way to get validation object, you can use normal validation rules in _properties but also can define and use rules more flexible,

    http://fuelphp.com/forums/discussion/8358/custom-validation-callbacks-in-orm-models

    maybe you define validation in 2 places but it is easy to use, is it wrong way to do such way?
  • HarroHarro
    Accepted Answer
    That example is a copy of the way you do validation with Model_Crud, and copied to an ORM model.

    It works, it is interchangable with Model_Crud, but it is not integrated in the ORM model, it doesn't use the model properties, and you can't combine it with for example the typing observer.

    It also requires manual validation, all that does is a method to define the validation object. ORM model validation runs completely automaticly, when you save the object.

    Both work, so it's up to you.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion