簡體   English   中英

ZF2路由在OS X上有效,但在Linux上失敗

[英]ZF2 Routing works on OS X but fails on linux

我有一個基於Zend Framework 2.3的小型站點,該站點在具有OS X Server的OS X上運行。 我需要做一些開發,所以我已經將其復制到Debian 7系統上。 除了數據庫定義外,兩台計算機上的代碼相同。 基於Linux的系統可用於大多數功能,但其中一個會導致404錯誤,我不知道為什么會這樣。 module.config.php是array('invokables'=> array('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')),'路由器'=>數組('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系統上的路由失敗?

我個人會嘗試通過更改第一個和最后一個參數的正則表達式來進行嘗試:

'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,因為找不到路由。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM