我有一个基于ZendFramework2.3的小站点,它运行在OSX和OSX服务器上。我需要做一些开发,所以我把它复制到了Debian7系统上。除了数据库定义之外,这两台机器上的代码都是相同的。基于Linux的系统适用于大多数功能,但有一个会导致404错误,我不明白为什么会这样。module.config.php是
阵列(
'invokables'=>数组(
'LibraryRest\Controller\AuthorRest'=>'LibraryRest\Controller\AuthorRestController',
'LibraryRest\Controller\BookTitleRest'=>'LibraryRest\Controller\BookTitleRestController',
'LibraryRest\Controller\RecentRest'=>'LibraryRest\Controller\RecentRestController'
),
'factories'=>数组(
'LibraryRest\Controller\SearchRest'=>'LibraryRest\Factory\SearchRestControllerFactory'
)
),
'路由器'=>阵列(
'路由'=>数组(
'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系统上的路由失败?
最佳答案
我个人会尝试更改第一个和最后一个参数的regex:
'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,因为找不到路由。