実際、正規表現ルートはそのことを行います。
何らかの理由で正規表現ルートを使用したくない場合は、フロント コントローラー プラグインを介した簡単な回避策があります。
//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] );
}
}
もちろん、必要に応じて同じ方法でタイトルを抽出することもできます。
URL を生成する場合は、'article' パラメータを作成することを忘れないでください。
$this->url( array( 'article' => $id.'_'.$title ) );