In order to not show the ID's of the members of my social network in the URL, I have created this route:
perfil_miembro:
url: /miembros/:nombre_apellidos
class: sfDoctrineRoute
options: { model: Usuario, type: object}
param: { module: miembros, action: show}
And added this line in the show action:
$this->usuario = $this->getRoute()->getObject();
It works OK: when I click on their names the corresponding profile is shown, and the URL is this type:
frontend_dev.php/miembros/Maria+de+Miguel+Alvarado
Now I would like to slug the names in the URL so I have changed the route this way:
perfil_miembro:
url: /miembros/:nombre_apellidos_slug
class: sfDoctrineRoute
options: { model: Usuario, type: object}
param: { module: miembros, action: show}
And I have created these methods:
public function getNombreApellidosSlug()
{
return Tirengarfio::slugify($this->getNombreApellidos());
}
class Tirengarfio
{
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;
}
}
Now when I click on the name of a member, this URL is shown:
frontend_dev.php/miembros/maria-de-miguel-alvarado
But it always shows the profile of the first member that I have in the fixtures file.
How can I make it work?
Ubuntu 8.04 - Symfony 1.3.