0

私は多言語の Zend プロジェクトを開発しています。イベントを作成しているので、次のような構造を使用したい:

  • domain.com/event/2010/ => 2010 年のイベント
  • domain.com/event/2010/11/ => 2010 年 11 月のイベント
  • domain.com/event/2010/11/23/ => 2010 年 11 月 23 日のイベント

このポピュズのために、次のルートを作成しました。

$router->addRoute('event', new Zend_Controller_Router_Route_Regex('event/(\d+)(/(\d+)(/(\d+))?)?', array(
                    'module' => 'public',
                    'controller' => 'event',
                    'action' => 'show'
                )));

$router->addRoute('eventLang', new Zend_Controller_Router_Route_Regex(':language/event/(\d+)(/(\d+)(/(\d+))?)?', array(
                    'language'=>'en'
                    'module' => 'public',
                    'controller' => 'event',
                    'action' => 'show'
                )));

最初のものは完璧に機能します。2 つ目は、「action 2010 does not exist」のようなエラーを表示します。ここで何が問題ですか?

4

1 に答える 1

1

:languageZend_Controller_Router_Route_Regex で変数 (あなたの場合) を使用することはできません。次の方法で正規表現を書き換える必要があります。

$router->addRoute('eventLang', new Zend_Controller_Router_Route_Regex('[^/]+/event/(\d+)(/(\d+)(/(\d+))?)?', array(
    'module' => 'public',
    'controller' => 'event',
    'action' => 'show'
), array(
    1 => 'language'
));
于 2011-08-21T16:53:57.350 に答える