Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony] I18n - Admin generator obsługuje I18n ale nie do konca poprawnie
stachuf11
post 13.04.2008, 09:17:10
Post #1





Grupa: Zarejestrowani
Postów: 154
Pomógł: 1
Dołączył: 24.04.2006

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


witam
są nastepujace tabele w schema.yml

statusyfirmy:
_attributes: { phpName: Statusyfirmy }
id:
ustawienia: varchar(50)

statusyfirmy_i18n:
_attributes: { phpName: StatusyfirmyI18n }
nazwa: varchar(50)

czyli druga do obsługi wersji jezykowej

w adminie inicjuje modul
symfony propel-init-admin backend statusyfirmy Statusyfirmy

pozniej w generator.yml robie wpisy


list:
display: [ id, nazwa ]

edit:
display: [ id, nazwa ]
fields:
nazwa: { params: disabled= false }

i ustawiam w

myproject/lib/model/Statusyfirmy.php

public function hydrate(ResultSet $rs, $startcol = 1)
{
parent::hydrate($rs, $startcol);
$this->setCulture(sfContext::getInstance()->getUser()->getCulture());
}

aby był ustawiony jezyk dla obiektu

generator ogolnie zachowuje sie ok, moge edytowac pole nazwa, zapisuje zmiany, ale
nie dzial ado konca poprawnie przy dodawaniu rekordu, gdy dodaje rekord, to za pierwszą probą zapisu zapisuje sie rekord główny, a wartosc w polu nazwa nie, czyli nie zapisuje w tabeli i18n, dopiero przy drugiej probie zapisu zapisuje sie sie wartosc w polu nazwa czyli w tabeli I18n, czy jest na to rozwiazanie?
ja pracuje jeszcze w wersji symfony 1.0
Go to the top of the page
+Quote Post
vezyr
post 13.04.2008, 10:24:56
Post #2





Grupa: Zarejestrowani
Postów: 12
Pomógł: 3
Dołączył: 12.06.2007
Skąd: Głogów

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


Witam.
Wydaje mi się, że już Twoja schema jest nie do końca proprawna. W tabeli statusyfirmy_i18n brakuje chociażby pola culture, które odpowiadałoby za określenie, w jakim języku jest dany wpis. Zobacz sobie na: http://www.symfony-project.org/book/1_0/13...d-L10n#Creating Localized Schema://http://www.symfony-project.org/book...ocalized Schema://http://www.symfony-project.org/book...ocalized Schema. Ja podam tutaj swój sposób, który (przynajmniej u mnie winksmiley.jpg ) działa i nie zauważyłem jeszcze z nim żadnych problemów.
Moja schema:
  1. <?php
  2. _attributes: { phpName: Link, isI18N: true, i18nTable: link_i18n }
  3. id: { type: integer, required: true, primaryKey: true, autoincrement: true }
  4. category_id: { type: integer, required: true, foreignTable: link_category, foreignReference: id }
  5. user_id:  { type: integer, required: true, foreignTable: sf_guard_user, foreignReference: id }
  6. url:  { type: varchar, size: 255 }
  7. created_at:
  8.  
  9. link_i18n:
  10. _attributes: { phpName: LinkI18N }
  11. id: { type: integer, required: true, primaryKey: true, foreignTable: link, foreignReference: id }
  12. culture:  { isCulture: true, type: varchar, size: 7, required: true, primaryKey: true }
  13. title:  varchar(250)
  14. description: { type: longvarchar }
  15. ?>


Generator.yml:
  1. <?php
  2. generator:
  3. class: sfPropelAdminGenerator
  4. param:
  5. model_class: Link
  6. theme: default
  7.  
  8. list:
  9. display: [id, category, user, title, url, created_at]
  10. fields:
  11. category:
  12. params: disabled=false
  13. object_actions:
  14. _edit: ~
  15. _delete: ~
  16. filters: [category]
  17.  
  18. edit:  
  19. display:
  20. "Overall": [category_id, user_id, url, created_at]
  21. "Title":
  22. - title_i18n_pl
  23. - title_i18n_en
  24. "Description":
  25. - description_i18n_pl
  26. - description_i18n_en
  27. fields:
  28. description_i18n_pl:
  29. name: Polish 
  30. type: textarea_tag
  31. params: disabled=false size=100x4 rich=true
  32.  
  33. description_i18n_en:
  34. name: English
  35. type: textarea_tag
  36. params: disabled=false size=100x4 rich=true
  37.  
  38. title_i18n_pl:
  39. name: Polish
  40. params: disabled=false
  41.  
  42. title_i18n_en:
  43. name: English
  44. params: disabled=false
  45. ?>


Do tego wszystkiego, w /lib/model/om/ stworzyłem dodatkową klasę, nazwaną i18nBaseClass:
  1. <?php
  2. class i18nBaseClass extends BaseObject
  3. {
  4. public function __construct()
  5. {
  6. $this->setCulture(sfContext::getInstance()->getUser()->getCulture());
  7. }
  8. }
  9. ?>


W klasie /lib/model/om/BaseLink.php zmieniłem klasę-rodzica na swoją, utworzoną przed chwilą i18nBaseClass:
  1. <?php
  2. abstract class BaseLink extends i18nBaseClass implements Persistent {
  3. ...
  4. }
  5. ?>


I na konieć, do klasy /lib/model/Link.php dodałem taki kod:
  1. <?php
  2. /**
  3.  * Subclass for representing a row from the 'link' table.
  4.  *
  5.  * 
  6.  *
  7.  * @package lib.model
  8.  */ 
  9. class Link extends BaseLink
  10. {
  11. function __call($methodName, $params)
  12. {
  13. $nameTab = @explode('I18n', $methodName, 2);
  14.  
  15. if(count($nameTab) == 2)
  16. {
  17. list ($method, $culture) = $nameTab;
  18. $this->setCulture($culture);
  19. return call_user_func_array(array($this, $method), $params);
  20. }
  21. else
  22. return parent::__call($methodName, $params);
  23. }
  24. }
  25. ?>


I to by było na tyle. Na razie nie zauważyłem problemów z działaniem przy takiej metodzie winksmiley.jpg
Pozdrawiam.

Ten post edytował vezyr 13.04.2008, 10:25:30
Go to the top of the page
+Quote Post
stachuf11
post 13.04.2008, 10:52:22
Post #3





Grupa: Zarejestrowani
Postów: 154
Pomógł: 1
Dołączył: 24.04.2006

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


schemat jest ok, nie trzeba definiowac tych pol culture i id w pliku schema.yml, dodawane są automatem, pisze to w dokumentacji I18n,
natomiast dziekuje Tobie za pomoc w moim temacie

pozdrawiam serdecznie

Ten post edytował stachuf11 13.04.2008, 11:06:52
Go to the top of the page
+Quote Post
vezyr
post 13.04.2008, 12:42:51
Post #4





Grupa: Zarejestrowani
Postów: 12
Pomógł: 3
Dołączył: 12.06.2007
Skąd: Głogów

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


Cytat(stachuf11 @ 13.04.2008, 11:52:22 ) *
schemat jest ok, nie trzeba definiowac tych pol culture i id w pliku schema.yml, dodawane są automatem, pisze to w dokumentacji I18n,

Fakt, tym razem moje niedopatrzenie smile.gif Faktycznie można je pominąć i zostaną one automatycznie wstawione.

Cytat(stachuf11 @ 13.04.2008, 11:52:22 ) *
natomiast dziekuje Tobie za pomoc w moim temacie

Proszę bardzo smile.gif
Pozdrawiam.

Ten post edytował vezyr 13.04.2008, 12:43:45
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 13.08.2025 - 23:05