kicaj
4.08.2009, 11:24:56
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?
ZenekN
19.03.2014, 16:28:17
Stary kotlet ale jary!
Jak rozwiązałeś problem sprzed 4 lat ;T ?
kicaj
19.03.2014, 18:50:48
Wyciąg z metody szukającej po slug'u - może się przyda:
function findBySlug($slug = '', $field = 'slug') {
$alias = $this->alias . '.' . $field;
// Sprawdza czy Model uzywa Translate Behavior oraz czy pole $field jest dodane jako tlumaczone
if (isset($this->actsAs['Translate']) && in_array($field, $this->actsAs['Translate'])) { $alias = 'I18n__' . $field;
if (Configure::read('Config.language') !== DEFAULT_LANGUAGE) {
$alias .= '__' . $this->locale[0];
}
$alias .= '.content';
}
$result = $this->find('first', array( $alias => $slug
)
));
if (empty($result) && Configure
::read('Config.language') !== DEFAULT_LANGUAGE
) { // Pobiera rekord dla domyslnego rekordu
$result = $this->find('first', array( str_replace('__' . Configure
::read('Config.language'), '__' . DEFAULT_LANGUAGE
, $alias) => $slug, )
));
}
return $result;
}
kleus
20.03.2014, 13:22:35
Trochę się naszukałem ale znalazłem
https://github.com/joostdekeijzer/CakePHP-I18nSearchKiedyś mi pomogło