1

我是 Zend 框架的初学者,因此非常感谢您帮助我理解为什么找不到我的正则表达式路由规则。这是规则:

    // Picture: www.mywebsite.com/gallery/12/pic/45/my-beautiful-picture.html
    $router->addRoute('picture',
            new Zend_Controller_Router_Route_Regex(
                    'gallery/(\d+)/pic/(\d+)/([A-Za-z0-9.]+)',
                    array(
                            'module'=>'frontoffice',
                            'controller'=>'gallery',
                            'action'=>'picture'
                    ),
                    array(
                            1 => 'gallery_id',
                            2 => 'picture_id',
                            3 => 'title'
                    ),
                    'gallery/%d/pic/%d/%s'
            )
    );

当我访问页面 www.mywebsite.com/gallery/1/pic/9/my-beautiful-picture.html 时,我收到以下错误消息:

 An error occurred
 Page not found
 Exception information:

 Message: Action "1" does not exist and was not trapped in __call()
 Stack trace:

 #0 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Action.php(518): Zend_Controller_Action->__call('1Action', Array)
 #1 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('1Action')
 #2 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
 #3 /usr/local/zend/share/ZendFramework/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
 #4 /usr/local/zend/share/ZendFramework/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
 #5 /var/www/misterjules/public/index.php(27): Zend_Application->run()
 #6 {main}  

 Request Parameters:

 array (
    'controller' => 'gallery',
    'action' => '1',
    'pic' => '9',
    'module' => 'frontoffice',
 )  

我的其他正则表达式路由规则(之前写在脚本中)如下:

    // *** GALLERY ***
    // Galleries (index): www.mywebsite.com/gallery
    $router->addRoute('galleries',
            new Zend_Controller_Router_Route_Regex(
                    'gallery(/page=(\d+))?',
                    array(
                            'module'=>'frontoffice',
                            'controller'=>'gallery',
                            'action'=>'galleries'
                    ),
                    array(
                            2 => 'page',
                    ),
                    'gallery'
            )
    );

    // a gallery index: www.mywebsite.com/gallery/13/my-travel-in-dublin.html
    //                  OR www.mywebsite.com/gallery/13/my-travel-in-dublin.html/page=4
    $router->addRoute('gallery',
            new Zend_Controller_Router_Route_Regex(
                    'gallery/(\d+)/([A-Za-z0-9.]+)(/page=(\d+))?',
                    array(
                            'module'=>'frontoffice',
                            'controller'=>'gallery',
                            'action'=>'gallery'
                    ),
                    array(
                            1 => 'gallery_id',
                            2 => 'title',
                            4 => 'page'
                    ),
                    'gallery/%d/%s'
            )
    );

我不明白我的错误在哪里。

谢谢你的帮助。

朱尔斯

4

1 回答 1

1

您的正则表达式似乎缺少匹配所需的破折号gallery/12/pic/45/my-beautiful-picture.html

试试这个:

$router->addRoute('picture',
        new Zend_Controller_Router_Route_Regex(
                'gallery/(\d+)/pic/(\d+)/([A-Za-z0-9.-]+)', #etc.
于 2012-06-17T09:54:59.677 回答