En effet, une route regex ferait l'affaire.
Si pour une raison quelconque vous ne voulez pas utiliser la route regex, il existe une solution simple, via un plugin de contrôleur frontal:
//replace the :id and :title params with a single one, mapping them both
$newsroute = new Zend_Controller_Router_Route(
'news/:action/:article',
array('controller' => 'news')
);
// in a front controller plugin, you extract the Id form the article param
function function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
if($request->getParam('article', false)){
$slug = $request->getParam('article');
$parts = array();
preg_match('/^(\d+)/', $slug, $parts);
// add the extracted id to the request as if there where an :id param
$request->setParam('id', $parts[0]);
}
}
Bien sûr, vous pouvez également extraire le titre de la même façon si vous besoin de ça.
Ne pas oublier de construire votre « article » quand vous voulez param pour générer urls:
$this->url(array('article' => $id.'_'.$title));
lien à droite: https://github.com/agutoli/CharConvert – JellyBelly