Tuesday, June 18, 2013

Re: Switch "validation set" within model?


class Sites extends AppModel {

     public function dataValidate1(){
              $validatevar = array(
                     'firstname' => array(
                          'mustNotEmpty' => array(
                          'rule' => 'notEmpty',
                          'message' => 'Please enter your First Name')
                      )
                );
             $this->validate = $validatevar;
              return $this->validates();    
     }
     public function dataValidate2(){
              $validatevar = array(
                     'firstname' => array(
                          'mustNotEmpty' => array(
                          'rule' => 'notEmpty',
                          'message' => 'Please enter your First Name')
                      ),
                      'lastname' => array(
                          'mustNotEmpty' => array(
                          'rule' => 'notEmpty',
                          'message' => 'Please enter your First Name')
                      )
                );
             $this->validate = $validatevar;
              return $this->validates();    
     }
}

In controller:
if ($this->Sites->dataValidate1()) {   <------- Change to whatever validate function?
                $this->Sites->save($this->request->data, false);
                $this->Session->setFlash(__('Your account has been successfully updated'),'default',array('class'=>'alert succes_msg'));
                $this->redirect('/admin/sites/account');
}

Works for me Not sure if its right or proper (still new to cake)
       

Eric

On Thursday, June 13, 2013 2:55:08 AM UTC-4, LDSign wrote:
Hi

I would liket to switch a complete "validation set" for a model (in the controller). Deeper levels of the application requires more and more user data, so I had the idea to define multiple validation sets within the models for each level.

Best solution will be an automatic switch for a specified action.

Ive already searched a litte and found this:


Unfortunatley this is for Cake 1.2 - does anyone have a working solution for 2.3.6?

Or is there a better approach of doing this?

Thanks,
Frank

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: