Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SF2][SF] checkbox zawsze zaznaczony
wiciu010
post
Post #1





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

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


Cześć,

Mam checkbox w formularzu stworzony:
  1. $builder->add('is_active', 'checkbox', array('value'=>true ));


W kontrolerze ustawiam formularz:
  1. $form = $this->createForm(new AddClientType());
  2. $form->setData($user);


W modelu User, który mapuje tabelę User mam:
  1. /**
  2.   * Set is_active
  3.   *
  4.   * @param boolean $isActive
  5.   * @return User
  6.   */
  7. public function setIsActive($isActive)
  8. {
  9. $this->is_active = $isActive;
  10.  
  11. return $this;
  12. }
  13.  
  14. /**
  15.   * Get is_active
  16.   *
  17.   * @return boolean
  18.   */
  19. public function getIsActive()
  20. {
  21. return $this->is_active;
  22. }


W widoku twig mam:
Kod
{{ form_widget(generalForm.is_active, {'id':'is_active'}) }}


W bazie pole jest jako tinyint i przyjmuje wartość 1 albo 0. Niestety na stronie checkbox zawsze jest zaznaczony. Nawet jeśli w bazie jest ustawione 0. Jak to poprawić?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
blahy
post
Post #2





Grupa: Zarejestrowani
Postów: 82
Pomógł: 22
Dołączył: 20.07.2010

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


Pokaz cale AddClientType

Powinienes miec data_class ustawione na User,
tworzyc formularz w kontrollerze przez $this->createForm(new AddClientType(), $user);
a w type $builder->add('is_active', 'checkbox');

jezeli dalej checbkox jest zaznaczony to dla pewnosci w kontrollerze dumpnij $user->getIsActive() czy jest false.

no i czy generalForm to ten sam form co AddClientType?
Go to the top of the page
+Quote Post
wiciu010
post
Post #3





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

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


Cytat(blahy @ 20.08.2015, 23:28:08 ) *
Powinienes miec data_class ustawione na User,


Hm tego mogę nie miec. Jak to powinno być ustawiona?

Cytat(blahy @ 20.08.2015, 23:28:08 ) *
tworzyc formularz w kontrollerze przez $this->createForm(new AddClientType(), $user);


W ten sposób mi nie binduje danych z bazy, dlatego, aby uzupełnić formularz danymi musiałem zrobić:

  1. $form = $this->createForm(new AddClientType());
  2. $form->setData($user);

Go to the top of the page
+Quote Post

Posty w temacie


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: 4.10.2025 - 18:12