Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony] i problem z walidatorem unique
trucksweb
post
Post #1





Grupa: Zarejestrowani
Postów: 1 199
Pomógł: 31
Dołączył: 22.03.2004
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


tworze rejestracje uzytkownikow i zachcialo mi sie walidacji loginu, czyli login musi byc unikalny.Oczywiscie walidacja po stronie serwera.

Oto baza:
  1. CREATE TABLE IF NOT EXISTS `user` (
  2. `id` int(11) NOT NULL AUTO_INCREMENT,
  3. `name` varchar(250) NOT NULL,
  4. `surname` varchar(250) DEFAULT NULL,
  5.  
  6. `login` varchar(250) NOT NULL,
  7.  
  8. PRIMARY KEY (`id`),
  9. UNIQUE KEY `login` (`login`),
  10. KEY `user_FI_1` (`role`)
  11. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;



to klasa formy:
-utworzylem sobie taka funkcyjke
  1.  
  2. protected function getLoginValidator()
  3. {
  4. return new sfValidatorAnd(array(new sfValidatorString(array('min_length' => 3,
  5. 'required' => true),
  6. array('min_length' => 'Login musi być dłuższy niż 3 znaki',
  7. 'required' => 'Podanie loginu jest wymagane')),
  8. new sfValidatorPropelUnique(array('model' => 'User',
  9. 'column' => array('login')),
  10. array('invalid'=>'Podany login już zajety. Prosimy wybrać inny.'))
  11. ));
  12. }


a na koncu
  1. $this->validatorSchema->setPostValidator($this->getLoginValidator($this->getValues()));



w kontrolerze mam natomiast:
  1. $this->form = new UserForm();
  2. $this->firmForm = new FirmForm();
  3.  
  4. if($request->isMethod('post'))
  5. {
  6.  
  7. $this->form->bind($request->getParameter($this->form->getName()));


w requescie jest przeslana tablica, ale problem pojawia sie z tym loginem (IMG:style_emoticons/default/dry.gif)

Cytat
You must pass an array parameter to the clean() method (this validator can only be used as a post validator).


siedze nad tym od 14 i juz nie mam sil zeby to rozwiazac samemu.Prosze o pomoc.






//edit

a jednak doszedlem sam.

oprocz mojej funkcji powinien byc rowniez zwykly walidator stringowy:

  1. $this->setValidators(array(
  2.  
  3. 'login' => new sfValidatorString(array('required' => true,
  4. 'min_length' => 3,
  5. 'max_length' => 25),
  6. array('min_length' => 'Numer telefonu komórkowego powinien składać się z min. 3. znaków',
  7. 'max_length' => 'Numer telefonu komórkowego nie może składać się więcej niż z 25. znaków')),


wtedy funkcja walidujaca:

  1. protected function getLoginValidator()
  2. {
  3. return new sfValidatorPropelUnique(array('model' => 'User',
  4. 'column' => 'login'),
  5. array('invalid'=>'Podany login już zajety. Prosimy wybrać inny.'));
  6. }


smiga az milo (IMG:style_emoticons/default/laugh.gif)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.12.2025 - 17:34