You could also setup up the framework of your validation rule in the
model itself. Then you can update the details in the controller as
Alan suggested. This could help in making sure the rule will fail by
default just in case your api doesn't actually change the rule
accordingly. Also, that way you won't necessarily need to update the
whole rule but rather just parts (ie just the message or the rule)

On Feb 27, 1:06 am, [email protected] wrote:
> interestingly enough, I actually came across this same need in my application.
>
>
>
> From inside the controller, I added this line
>
>
>
> $this->MyModel->validate['bid']=array('rule'=>array('range',$this->MyModel->minimum_bid-1,$this->MyModel->maximum_bid+1),'message'=>"Allowed
>  range for bid is {$this->MyModel->minimum_bid} - 
> {$this->MyModel->maximum_bid}");
>
> if ($this->MyModel->save($this->data)) {...}
>
>
>
> so the save function still runs the validate and I set the minimum and 
> maximum bid during the beforeFilter
>
>
>
> Hope this helps.
>
>
>
> Alan
>
> -------- Original Message --------
> Subject: How to dynamically create validation rules
> From: Kyle Decot <[email protected]>
> Date: Fri, February 26, 2010 11:28 am
> To: CakePHP <[email protected]>
> I am creating an API for my website and I want to create validation
> rules for my various methods based on some rows in my api_arguments
> table. How should I go about doing this? Thanks for any help.
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" 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 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" 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