That sounds familiar ;)

I wouldn't override validates, as on CakePHP 1.1 the parameter to
validates() has a different meaning to the one you are using, while in 1.2
validates() is supposed to take no parameters ($data parameter is
deprecated.)

I think it'd be better to have it as a separate function (something like
expects())

Also it wouldn't hurt to back the validation rules and restore after
validation. Once again, on AppModel:

function validateFields($fields)
{
        if (!isset($this->__backValidateRules))
        {
                $this->__backValidateRules = array();
        }

        $ignore = array_diff(array_keys($this->validate), $fields);
        
        foreach($ignore as $field)
        {
                $this->__backValidateRules[$field] =
$this->validate[$field];
                unset($this->validate[$field]);
        }
}

function validates($param)
{
        $validates = parent::validates($param);

        if (isset($this->__backValidateRules))
        {
                foreach($this->__backValidateRules as $field => $rule)
                {
                        $this->validate[$field] = $rule;
                }

                $this->__backValidateRules = array();
        }

        return $validates;
}

So this way after validation is performed rules are restored to their
original state.

PS: Note that I'm not doing anything with validates() parameter, I'm just
passing it through.

-MI

---------------------------------------------------------------------------

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar

-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de scragz
Enviado el: MiƩrcoles, 07 de Marzo de 2007 06:56 a.m.
Para: Cake PHP
Asunto: Re: Different Validations on 1 Table (Model) Based on the Action


This overrides built-in validates and allows you to pass an array of
field names that you want to check. Pretty much like the one above but
I didn't like how that one permanently changed the fields that were
set for model->validate. Bonus would be to make it so you could change
the rules by passing an assoc array of new rules.


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to