I have problem whit slugify routing parameter. I want to replace all intervals and symbols with "-". When parameter is with latin letters all work, but if I try to slugify parameter whit cyrillic letters I get 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 all non letters or digits by -
$text = preg_replace('/\W+/', '-', $text);
// trim and lowercase
$text = strtolower(trim($text, '-'));
return $text;
}
public function getNameSlug()
{
$text= Category::slugify($this->getName());
return $text;
}
Example:
i have two names in databace:
- english language
- Български език
Normally whitin function url is :
- english+language
- Български+език
When i put function result is :
- english-language
- and on cyrillic version parameter is empty.
Empty module and/or action after parsing the URL "/cat/1/" (/).
I recommend you to use Doctrine::urlize instead of your own slugify function (since your are using Doctrine).
And then, replace your function like:
edit:
In fact, it seems that Doctrine doesn’t well handle Cyrillic (even in the 2.0). You will have to handle it on your own. I found this function:
And then :