我有一个基于 Zend Framework 2.3 的小型站点,该站点在带有 OS X Server 的 OS X 上运行。我需要做一些开发,所以我将它复制到 Debian 7 系统上。除了数据库定义之外,两台机器上的代码是相同的。基于 Linux 的系统适用于大多数功能,但有一个会导致 404 错误,我不明白为什么会这样。 module.config.php 是 大批 ( '可调用'=>数组( 'LibraryRest\Controller\AuthorRest' => 'LibraryRest\Controller\AuthorRestController', 'LibraryRest\Controller\BookTitleRest' => 'LibraryRest\Controller\BookTitleRestController', 'LibraryRest\Controller\RecentRest' => 'LibraryRest\Controller\RecentRestController' ), '工厂'=>数组( '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 系统上可能导致路由失败的原因是什么?
最佳答案
我个人会尝试更改第一个和最后一个参数的正则表达式:
'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 段类中生成错误。由于存在错误,因此会导致 404,因为找不到路由。
关于linux - ZF2 Routing 在 OS X 上工作但在 linux 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38146447/