tags:

views:

541

answers:

2

I need to perform some validation. I don't have model in the application. Does anyone know how to do the validation without model? Can you show me using a small sample or statement?

+5  A: 

Honestly, I'd create a model just for the validation. You can create a model that doesn't use a table by adding

var $useTable = false;

And then create a validation array with rules for each field you want to validate:

var $validate = array('login' => 'alphaNumeric','email' => 'email','born' => 'date');

Then, in your controller, do something like:

$this->MyModel->set($this->data);
if($this->MyModel->validates()){
    // do stuff with valid data
}

If you really, really can't use a model, then you'll have to simply loop over each value in $this->data in your controller action and validate it against a regular expression or use the Validation::[rule]() stuff, like:

if(Validation::email($someThingThatMightBeAnEmailAddress)){
    // do stuff with valid email address.
}
inkedmn
A: 

I think my first question would be this: if you don't have a model...what are you validating? Typically data collection would be done to populate a model. If you're using an alternative data repository (file, web services, etc.), a model would still be the appropriate way to access and manipulate that data.

In short, in order to better answer this, I think a little more context would be helpful and maybe even necessary.

Rob Wilkerson