Tuesday, November 29, 2011

Re: How Check validate before save

Hi Mamdoohi,

As others have said when you call your models save() method it will
check validation by default. But if for whatever reasons you want to
do manual validation, here's a few methods that I found extremely
helpful:

$this->YourModel->set($this->request->data);
You can use your models set method(don't confuse this set() method
with the controllers set() method, they are two different methods) to
pass in data. This data won't actually be saved yet, and then you can
manually see if it validates with the following method:

$this->YourModel->validates();
After sending it to your model you can then check if the data you sent
validates using the models validates method. It'll return true or
false if it validated.

There's also a whole bunch of other model methods for validation and
for associated models in the api that you may find helpful:

http://api20.cakephp.org/class/model

On Nov 27, 12:02 am, Mamdoohi <hamid.mamdo...@gmail.com> wrote:
> hi
> I want validate data before save.
> my data is for two table so I want check validate then save data into two
> table
>
> how can do it?

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate