Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [CakePHP] Wyszukiwarka i i18n
kicaj
post
Post #1





Grupa: Zarejestrowani
Postów: 1 640
Pomógł: 28
Dołączył: 13.02.2003
Skąd: Międzyrzecz/Poznań

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


Jak zbudowac wyszukiwarke kiedy uzywam i18n i Translate Behavior?
Searchable Behavior nie pomaga tutaj...

Dokladniej: Problem polega na tym, ze mamy dwie tabele:
Products: id, created, modified...
I18n: id, model, name, foreign_key, content...

Nie mamy tutaj pol (np. name, description, etc.) w Products co sprawia problem przy uzywaniu skladni SQL LIKE, wiec jak rozwizac ten problem aby moc szukac? Mam na mysli najprostrza wyszukiwarke?
Go to the top of the page
+Quote Post
ZenekN
post
Post #2





Grupa: Zarejestrowani
Postów: 419
Pomógł: 5
Dołączył: 7.08.2012

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


Stary kotlet ale jary!

Jak rozwiązałeś problem sprzed 4 lat ;T ?
Go to the top of the page
+Quote Post
kicaj
post
Post #3





Grupa: Zarejestrowani
Postów: 1 640
Pomógł: 28
Dołączył: 13.02.2003
Skąd: Międzyrzecz/Poznań

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


Wyciąg z metody szukającej po slug'u - może się przyda:

  1. function findBySlug($slug = '', $field = 'slug') {
  2. $alias = $this->alias . '.' . $field;
  3.  
  4. // Sprawdza czy Model uzywa Translate Behavior oraz czy pole $field jest dodane jako tlumaczone
  5. if (isset($this->actsAs['Translate']) && in_array($field, $this->actsAs['Translate'])) {
  6. $alias = 'I18n__' . $field;
  7.  
  8. if (Configure::read('Config.language') !== DEFAULT_LANGUAGE) {
  9. $alias .= '__' . $this->locale[0];
  10. }
  11.  
  12. $alias .= '.content';
  13. }
  14.  
  15. $result = $this->find('first', array(
  16. 'conditions' => array(
  17. $alias => $slug
  18. )
  19. ));
  20.  
  21. if (empty($result) && Configure::read('Config.language') !== DEFAULT_LANGUAGE) {
  22. // Pobiera rekord dla domyslnego rekordu
  23. $result = $this->find('first', array(
  24. 'conditions' => array(
  25. str_replace('__' . Configure::read('Config.language'), '__' . DEFAULT_LANGUAGE, $alias) => $slug,
  26. )
  27. ));
  28. }
  29.  
  30. return $result;
  31. }


Ten post edytował kicaj 19.03.2014, 18:51:59
Go to the top of the page
+Quote Post
kleus
post
Post #4





Grupa: Zarejestrowani
Postów: 93
Pomógł: 7
Dołączył: 22.10.2009
Skąd: Siędzę

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


Trochę się naszukałem ale znalazłem
https://github.com/joostdekeijzer/CakePHP-I18nSearch

Kiedyś mi pomogło
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: 24.08.2025 - 15:08