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:

<?php
protected function createRawSlug()
{
    return '' . $this->cleanupSlugPart($this->getTitle()) . '';
}

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:

<?php
protected function createRawSlug()
{
    $title = $this->getTitle();
    
    $replacements = array(
        'Ä' => 'Ae',
        'Ö' => 'Oe',
        'Ü' => 'Ue',
        'ä' => 'ae',
        'ö' => 'oe',
        'ü' => 'ue',
        'ß' => 'ss'
    );
     
    $title = str_replace(array_keys($replacements), array_values($replacements), $title);
    
    return '' . $this->cleanupSlugPart($title) . '';
}

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:

<?php
protected function createRawSlug()
{
    $title = $this->getTitle();
    $title = Skoch_Translit::trans($title);
    return '' . $this->cleanupSlugPart($title) . '';
}
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 stefan@eliteinformatiker.de.