Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Validation with Model_Crud
  • I've been using ORM for a while and it works great. But now I have to develop a quite complex web app so I prefer to use plain SQL and no ORM anymore. But I really love the integration with the Fieldset and Validation class, and I'd like to be able to use that the same way. I've created a model "Model_Crud style" (http://dev-docs.fuelphp.com/classes/model_crud/introduction.html) and I've set the rules in the protected static $_rules variable:
    protected static $_rules = array('name' => 'required|min_length[50]');
    

    When I run the validation, the output is just true of false (the input passes the rules or not):
    $model = new Model_Test;
    $model->name = 'this value is too short';
    $model->validation()->run(); //outputs false, which is OK
    

    But now I try to get the error message, which fails. I've tried:
    $model->validation()->show_errors();
    

    But a var_dump() gives me an empty string (string '' (length=0)) What am I doing wrong?
  • What does the validation() method do? Can you post some code on http://scrp.at ?
  • Hi Harro, the validation() method gives me: http://scrp.at/bAz
    then the run() method gives me just boolean false.
    my model: http://scrp.at/bAA
    my controller: http://scrp.at/bAB
  • Hmmm. Which version of FuelPHP are you on? I've just copied your code into a test installation of 1.3/develop (should be equal to 1.2.1/release), and it works without problems.
    echo $drivingSchool->validation()->show_errors();
    

    gives me "The field name has to contain at least 2 characters." If you're doesn't give any output, what does
    \Debug::dump($drivingSchool->validation()->error());
    

    give you (it should be an array with 1 Validation_Error object).

Howdy, Stranger!

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

In this Discussion