Hello!
I have read in a post about the Validator script at
http://www.webtest.wvu.edu/users/cbscharf/validator/, and given that I
had some problems with the wiki's advanced validation w/ params
(http://wiki.cakephp.org/tutorials:advanced_validation:advance_validation_with_parameters),
I thought to give it a try.
Given that I think that the method suggested at Validator's site
corrupts the MVC framework, I choose a different approach.
I did as follows:
(0.5 took a bottle of milk)
1. added it under app/controllers/components/validator.php
(1.5 added some sugar and flour to it)
2. then wrote my own my_validator.php component which does a
require_once(app/controllers/components/validator.php) and initializes
the main class, adds custom validation methods, etc
the __construct method is:
function __construct(&$obj, &$data){
if(is_object($obj))
$this->obj = $obj;
parent::__construct($obj, $obj->validate, $data[$obj->name]);
}
(3.5 put it in the owen)
3. finally I rewrote the validates function in app_model.php to use the
MyValidator class
my new validates method is:
function validates($data=array()){
if ( empty($data) ) {
$data = $this->data;
}
$v = new MyValidator($this, $data);
if( is_array($this->filters) )
$this->filter($this->filters, $v);
$this->invalidFields = $v->_validation_errors;
return $v->validates();
}
(4.5 but don't know when to take it off?! :) )
I think it should work now, but it does not. At least not with
scaffolding, because when I save a data it runs the validates method
found in cake/libs/model_php5.php. I thought to get it overwritten in
app_model.php, or is this because of scaffolding?
Second question: is this a good way to validate all the models? I think
to the parent::__construct($obj, $obj->validate, $data[$obj->name]);
part of my constructor. Will it validate in all of my models if I have
a complex request? (ie: $params['data']['User'] and
$params['data']['Posts'] too get validated?)
any ideas, suggestions?
V
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---