symfony1 - Symfony cyrillic routing slug -
i have problem whit slugify routing parameter. want replace intervals , symbols "-". when parameter latin letters work, if try slugify parameter whit cyrillic letters error.
routing:
cattests: url: /cat/:id/:name_slug class: sfdoctrineroute options: { model: categories, type: object } param: { module: categories, action: testsbycat } requirements: id: \d+ slug functions:
static public function slugify($text) { // replace non letters or digits - $text = preg_replace('/\w+/', '-', $text); // trim , lowercase $text = strtolower(trim($text, '-')); return $text; } public function getnameslug() { $text= category::slugify($this->getname()); return $text; } example: have 2 names in databace:
- english language
- Български език
normally whitin function url :
- english+language
- Български+език
when put function result :
- english-language
- and on cyrillic version parameter empty.
empty module and/or action after parsing url "/cat/1/" (/).
i recommend use doctrine::urlize instead of own slugify function (since using doctrine).
and then, replace function like:
public function getnameslug() { return doctrine_inflector::urlize($this->getname()); } edit:
in fact, seems doctrine doesn't handle cyrillic (even in 2.0). have handle on own. found this function:
public static function replacecyrillic ($text) { $chars = array( 'ґ'=>'g','ё'=>'e','є'=>'e','ї'=>'i','і'=>'i', 'а'=>'a', 'б'=>'b', 'в'=>'v', 'г'=>'g', 'д'=>'d', 'е'=>'e', 'ё'=>'e', 'ж'=>'zh', 'з'=>'z', 'и'=>'i', 'й'=>'i', 'к'=>'k', 'л'=>'l', 'м'=>'m', 'н'=>'n', 'о'=>'o', 'п'=>'p', 'р'=>'r', 'с'=>'s', 'т'=>'t', 'у'=>'u', 'ф'=>'f', 'х'=>'h', 'ц'=>'c', 'ч'=>'ch', 'ш'=>'sh', 'щ'=>'sch', 'ы'=>'y', 'э'=>'e', 'ю'=>'u', 'я'=>'ya', 'é'=>'e', '&'=>'and', 'ь'=>'', 'ъ' => '', ); return strtr($text, $chars); } and :
public function getnameslug() { $slug = category::replacecyrillic($this->getname()); return doctrine_inflector::urlize($slug); }
Comments
Post a Comment