ZF2路由在OS X上运行但在Linux

时间:2016-07-01 13:15:54

标签: linux macos zend-framework2 debian

我有一个基于Zend Framework 2.3的小站点,它在OS X上运行OS X Server。我需要做一些开发,所以我把它复制到Debian 7系统上。除了数据库定义之外,两台机器上的代码都是相同的。基于Linux的系统适用于大多数功能,但一个导致404错误,我不明白为什么这应该是。 module.config.php是  阵列(                 'invokables'=>阵列(                         'LibraryRest \ Controller \ AuthorRest'=> 'LibraryRest \控制器\ AuthorRestController',                         'LibraryRest \ Controller \ BookTitleRest'=> 'LibraryRest \控制器\ BookTitleRestController',                         'LibraryRest \ Controller \ RecentRest'=> 'LibraryRest \控制器\ RecentRestController'                 )                 '工厂'=>阵列(                         'LibraryRest \ Controller \ SearchRest'=> 'LibraryRest \厂\ SearchRestControllerFactory'                 )         )         'router'=>阵列(                 'routes'=>数组(

                    'author-rest' => array (
                            'type' => 'Segment',
                            'options' => array (
                                    // Change this to something specific to your module
                                    'route' => '/author-rest[/:id]',
                                    'constraints' => array (
                                            'id' => '[0-9]+' 
                                    ),
                                    'defaults' => array (
                                            'controller' => 'LibraryRest\Controller\AuthorRest' 
                                    ) 
                            ) 
                    )
                    ,
                    'booktitle-rest' => array (
                            'type' => 'Segment',
                            'options' => array (
                                    'route' => '/booktitle-rest[/:id]',
                                    'constraints' => array (
                                            'id' => '[0-9]+' 
                                    ),
                                    'defaults' => array (
                                            'controller' => 'LibraryRest\Controller\BookTitleRest' 
                                    ) 
                            ) 
                    ),
                    'recent-rest' => array (
                            'type' => 'Segment',
                            'options' => array (
                                    'route' => '/recent-rest',
                                    'defaults' => array (
                                            'controller' => 'LibraryRest\Controller\RecentRest' 
                                    ) 
                            ) 
                    ),
                    'search-rest' => array (
                            'type' => 'Segment',
                            'options' => array (
                                    'route' => '/search-rest[/:action[/:first][/:last]]',
                                    'constraints' => array (
                                            'first' => '[a-zA-Z0-9_-\s\x40%\.]*',
                                            'last' => '[a-zA-Z0-9_-\s\x40%]*',
                                            'action' => '[a-zA-Z][a-zA-Z0-9_-]*' 
                                    ),
                                    'defaults' => array (
                                            'controller' => 'LibraryRest\Controller\SearchRest' 
                                    ) 
                            ) 
                    ) 
            ) 
    ),
    'view_manager' => array (
            'strategies' => array (
                    'ViewJsonStrategy' 
            ) 
    ) 

); 在linux机器上失败的路由是search-rest,因此http://mysite/search-rest/search/John/Smith会产生404.此模块中的所有其他路由在两个系统上都能正常工作。

Linux系统上可能导致路由失败的原因是什么?

1 个答案:

答案 0 :(得分:0)

我个人会尝试更改第一个和最后一个参数的正则表达式:

'search-rest' => array (
        'type' => 'Segment',
        'options' => array (
            'route' => '/search-rest[/:action[/:first][/:last]]',
            'constraints' => array (
                'first' => '[a-zA-Z0-9_\-\s\x40%\.]*',
                'last' => '[a-zA-Z0-9_\-\s\x40%]*',
                'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
            ),
            'defaults' => array (
                'controller' => 'LibraryRest\Controller\SearchRest'
                )
            )
        ),

我添加了一个" \"就在" - "之前或者您可以尝试将" - "在字符类([])的开头。

因为现在它在内部调用preg_match()函数时会在ZF Segment类中生成错误。由于存在错误,因此导致404无法找到路径。