cake-php@googlegroups.com
[Top] [All Lists]

Re: Problems using unbindValidation

Subject: Re: Problems using unbindValidation
From: euromark
Date: Wed, 9 Feb 2011 07:26:24 -0800 PST
put your method in app_model.php!


On 9 Feb., 15:48, John Andersen <j.andersen...@xxxxxxxxx> wrote:
> Note that you state:
>
> > in my app_controller I put the function:
>
> and then you use the function as:
>
> >         $this->User->unbindValidation('keep', array('usr_vorname',
> > 'usr_nachname'), true);
>
> In my eyes, it looks like you want to invoke the method in the User
> model, but it doesn't exist there.
> Please correct your code.
> Enjoy,
>    John
>
> On 9 Feb., 13:01, heohni <heidi.anselstet...@xxxxxxxxxxxxxxxxx> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > in my app_controller I put the function:
>
> > function unbindValidation($type, $fields, $require=false){
> >         if ($type === 'remove'){
> >             $this->validate = array_diff_key($this->validate,
> > array_flip($fields));
> >         }else if ($type === 'keep'){
> >             $this->validate = array_intersect_key($this->validate,
> > array_flip($fields));
> >         }
>
> >         if ($require === true){
> >             foreach ($this->validate as $field=>$rules){
> >                 if (is_array($rules)){
> >                     $rule = key($rules);
> >                     $this->validate[$field][$rule]['required'] = true;
> >                 } else{
> >                     $ruleName = (ctype_alpha($rules)) ? $rules :
> > 'required';
> >                     $this->validate[$field] =
> > array($ruleName=>array('rule'=>$rules,'required'=>true));
> >                 }
> >             }
> >         }
> >     }
>
> > in my user.php model I added an array
> > var $validate = array(.....
> > with all my rules, which are working fine!
>
> > No I want to use the unbindValidation function within my edit function
> > form the users_controller:
>
> >  function edit($id = NULL){
> >         $this->User->unbindValidation('keep', array('usr_vorname',
> > 'usr_nachname'), true);
>
> >         if(empty($this->data)){
> >             $this->data = $this->User->read(NULL, $id);
> >             $this->set('user', $this->User->read(NULL, $id));
> >         }else{
> >             if($this->User->save($this->data)){
> >                 $this->Session->setFlash('Alle Änderungen wurden
> > erfolgreich übernommen');
> >                 $this->redirect(array('action'=>'index'));
> >             }
> >         }
> >     }
>
> > But when I submit the form, I get the following message:
>
> > Warning (512): SQL Error: 1064: You have an error in your SQL syntax;
> > check the manual that corresponds to your MySQL server version for the
> > right syntax to use near 'unbindValidation' at line 1 [CORE\cake\libs
> > \model\datasources\dbo_source.php, line 684]
>
> > Why is that?
> > What do I have wrong?
>
> > Please advise!!

-- 
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@xxxxxxxxxxxxxxxx For more options, visit this group at 
http://groups.google.com/group/cake-php

<Prev in Thread] Current Thread [Next in Thread>