Propel: Replacing umlauts in sluggable behavior
Propel ships with a sluggable behavior taking care of creating urls from your titles and stuff. To create these urls, it uses iconv.
Yet, as iconv seems to cause problems pretty often, you might have to implement the replacement rules by yourself.
You have two possibilities:
- Either you override createRawSlug()
- Or you override cleanupSlugPart()
The first one is basically just a wrapper calling the latter one, which includes all the magic happening. So if you want to keep Propel’s implementation on replacing unknown characters with a string given in the schema.xml, you would override createRawSlug() (which is also what I did).
The standard propel implementation looks like this:
As Propel calls getTitle() itself there, we cannot use this method but have to copy the whole line. So a very basic implementation for replacing German umlauts correctly would be:
Of course it would be better to create a dedicated replacement method which can handle the creation of slugs throughout all classes, so that the code within createRawSlug() is reduced to the following:I do not maintain a comments section. If you have any questions or comments regarding my posts, please do not hesitate to send me an e-mail to email@example.com.