Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Symfony] problem z autogenerowanymi formularzami (admin generator)
Forum PHP.pl > Forum > PHP > Frameworki
dantes
Witam, mam problem związany z modyfikacją formularza stworzonego za pomocą admin-generatora.
Tak wygląda opis obiektu Query w schema.yml:
  1. query:
  2. id:
  3. created_at:
  4. status_changed_at: { type: TIMESTAMP }
  5. client_id: { type: integer, foreignTable: sf_guard_user, foreignReference: id,required: true }
  6. supervisor_id: { type: integer, foreignTable: sf_guard_user, foreignReference: id,required: true }
  7. villa_id:
  8. name: { type: VARCHAR, size: '50', required: true }
  9. email: { type: VARCHAR, size: '50', required: true }
  10. phone_no: { type: VARCHAR, size: '50', required: true }
  11. mobile_no: { type: VARCHAR, size: '50', required: true }
  12. skype: { type: VARCHAR, size: '100', required: true }
  13. period_from: { type: TIMESTAMP, required: true }
  14. period_to: { type: TIMESTAMP, required: true }
  15. nights_no: { type: INTEGER, required: true }
  16. message: { type: LONGVARCHAR, required: true }
  17. family_info: { type: LONGVARCHAR, required: true }
  18. owner_message: { type: LONGVARCHAR, required: true }
  19. adult_no: { type: INTEGER, required: true }
  20. children_no: { type: INTEGER, required: true }
  21. children_age: { type: VARCHAR, size: '50', required: true }
  22. ip: { type: VARCHAR, size: '25', required: true }
  23. status: { type: VARCHAR, size: '1', required: true, default: '0' }
  24. visible: { type: BOOLEAN, required: true, default: true }

Tak wygląda generator.yml w /backend/modules/query/config/:
  1. generator:
  2. class: sfPropelAdminGenerator
  3. param:
  4. model_class: Query
  5. theme: default
  6. fields:
  7. created_at: { name: Utworzono, params: class="cal" }
  8. status_changed_at: { name: Status zmieniono }
  9. client_id: { name: Klient }
  10. supervisor_id: { name: Opiekun }
  11. villa_id: { name: ID willi }
  12. name: { name: Imię i nazwisko }
  13. phone_no: { name: Nr tel. stacjonarny }
  14. mobile_no: { name: Nr tel. komórkowy }
  15. period_from: { name: Przyjazd }
  16. period_to: { name: Wyjazd }
  17. nights_no: { name: Liczba nocy }
  18. message: { name: Treść wiadomości }
  19. family_info: { name: Info o rodzinie }
  20. owner_message: { name: Wiadomość dla gospodarza }
  21. adult_no: { name: Liczba dorosłych }
  22. children_no: { name: Liczba dzieci }
  23. children_age: { name: Wiek dzieci }
  24. ip: { name: IP }
  25. visible: { name: Widoczny }
  26. edit:
  27. title: Edycja zapytania %%id%%
  28. display:
  29. "Willa": [villa_id]
  30. "Przebieg": [status,created_at,status_changed_at]
  31. "Użytkownicy": [client_id, supervisor_id]
  32. "Dane personalne": [name, email, phone_no, mobile_no, skype]
  33. "Zakres dat": [period_from, period_to]
  34. "Goście": [adult_no, children_no, children_age, family_info]
  35.  

Do takiego obiektu został wygenerowany formularz BaseQueryForm.class.php w /lib/form/base:
  1. class BaseQueryForm extends BaseFormPropel
  2. {
  3. public function setup()
  4. {
  5. $this->setWidgets(array(
  6. 'id' => new sfWidgetFormInputHidden(),
  7. 'created_at' => new sfWidgetFormDateTime(),
  8. 'status_changed_at' => new sfWidgetFormDateTime(),
  9. 'client_id' => new sfWidgetFormPropelChoice(array('model' => 'sfGuardUser', 'add_empty' => false)),
  10. 'supervisor_id' => new sfWidgetFormPropelChoice(array('model' => 'sfGuardUser', 'add_empty' => false)),
  11. 'villa_id' => new sfWidgetFormPropelChoice(array('model' => 'Villa', 'add_empty' => true)),
  12. 'name' => new sfWidgetFormInput(),
  13. 'email' => new sfWidgetFormInput(),
  14. 'phone_no' => new sfWidgetFormInput(),
  15. 'mobile_no' => new sfWidgetFormInput(),
  16. 'skype' => new sfWidgetFormInput(),
  17. 'period_from' => new sfWidgetFormDateTime(),
  18. 'period_to' => new sfWidgetFormDateTime(),
  19. 'nights_no' => new sfWidgetFormInput(),
  20. 'message' => new sfWidgetFormTextarea(),
  21. 'family_info' => new sfWidgetFormTextarea(),
  22. 'owner_message' => new sfWidgetFormTextarea(),
  23. 'adult_no' => new sfWidgetFormInput(),
  24. 'children_no' => new sfWidgetFormInput(),
  25. 'children_age' => new sfWidgetFormInput(),
  26. 'ip' => new sfWidgetFormInput(),
  27. 'status' => new sfWidgetFormInput(),
  28. 'visible' => new sfWidgetFormInputCheckbox(),
  29. ));
  30.  
  31. $this->setValidators(array(
  32. 'id' => new sfValidatorPropelChoice(array('model' => 'Query', 'column' => 'id', 'required' => false)),
  33. 'created_at' => new sfValidatorDateTime(array('required' => false)),
  34. 'status_changed_at' => new sfValidatorDateTime(array('required' => false)),
  35. 'client_id' => new sfValidatorPropelChoice(array('model' => 'sfGuardUser', 'column' => 'id')),
  36. 'supervisor_id' => new sfValidatorPropelChoice(array('model' => 'sfGuardUser', 'column' => 'id')),
  37. 'villa_id' => new sfValidatorPropelChoice(array('model' => 'Villa', 'column' => 'id', 'required' => false)),
  38. 'name' => new sfValidatorString(array('max_length' => 50)),
  39. 'email' => new sfValidatorString(array('max_length' => 50)),
  40. 'phone_no' => new sfValidatorString(array('max_length' => 50)),
  41. 'mobile_no' => new sfValidatorString(array('max_length' => 50)),
  42. 'skype' => new sfValidatorString(array('max_length' => 100)),
  43. 'period_from' => new sfValidatorDateTime(),
  44. 'period_to' => new sfValidatorDateTime(),
  45. 'nights_no' => new sfValidatorInteger(),
  46. 'message' => new sfValidatorString(),
  47. 'family_info' => new sfValidatorString(),
  48. 'owner_message' => new sfValidatorString(),
  49. 'adult_no' => new sfValidatorInteger(),
  50. 'children_no' => new sfValidatorInteger(),
  51. 'children_age' => new sfValidatorString(array('max_length' => 50)),
  52. 'ip' => new sfValidatorString(array('max_length' => 25)),
  53. 'status' => new sfValidatorString(array('max_length' => 1)),
  54. 'visible' => new sfValidatorBoolean(),
  55. ));
  56.  
  57. $this->widgetSchema->setNameFormat('query[%s]');
  58.  
  59. $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  60.  
  61. parent::setup();
  62. }
  63.  
  64. public function getModelName()
  65. {
  66. return 'Query';
  67. }
  68.  
  69.  
  70. }


Zaś ja chciałem zmodyfikować pola z datą, tzn. created_at, status_changed_at, period_from i period_to. Zacząłem więc od powyższego:
QueryForm.class.php w lib/form
  1. class QueryForm extends BaseQueryForm
  2. {
  3. public function configure()
  4. {
  5. $this->widgetSchema['period_from'] = new sfWidgetFormJQueryDate(array(
  6. 'image'=>'/images/icons/calendar_view_month.gif',
  7. 'format' => '%day%/%month%/%year%')
  8. );
  9. }
  10. }


Niestety, nie przynosi to żadnego efektu. Mało tego, wprowadzanie jakiejkolwiek zmiany do QueryForm, a nawet BaseQueryForm (tak, wiem, że się nie powinno, ale tylko do testu smile.gif jak np. usunięcie widżetu, zmiana widżetu daty na zwykły input, nic nie zmienia. Tak, mam: podłączone jquery, jquery-ui, style do jquery-ui, zainstalowany plugin sfFormExtraPlugin. Plugin do "layout" do jquery działa świetnie. Czy ktoś wie może, czemu modyfikacja tych formularzy nie zmienia mi widoku edycji w admin generatorze?
destroyerr
A z jakiej wersji sf korzystasz? Domyślam się, że z 1.1 i jeśli mam rację to jest podstawowy błąd. Wybierz albo wersję wcześniejszą albo późniejszą.

Czy listy wyboru dat zmieniają się na zwykłe pola (<input type="text" />)? Czy są jakieś błędy js?
dantes
Zapomniałem napisać winksmiley.jpg symfony 1.2.8, nie nie ma żadnych błędów js, konsola ff jest czysta winksmiley.jpg
Nie, nie jestem w stanie zmienić widżeta na zwykłe pole tekstowe.
destroyerr
Coś jest nie tak, struktura pliku generator.yml nie przypomina tej z wersji 1.2. Masz włączony plugin sfCompat10Plugin? Przepisz plik generator.yml tak, aby odpowiadał wersji 1.2.
dantes
Dzięki, rzeczywiście, przepisanie generator.yml pomogło. Wcześniej nie zwróciłem na to uwagi, bo przy konwersji z 1.1.4 do 1.2.8 wszystko działało, aż do teraz winksmiley.jpg
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.