簡體   English   中英

Zend Framework中模塊的URI路由遇到問題

[英]Having trouble with URI routing for modules in Zend Framework

我只是從Zend Framework開始,我不確定URI路由做錯了什么。

我將從htdocs文件夾中的Zend Studio中的初始Zend Framework項目開始(我在Windows 7上也使用Zend Server)。 到目前為止,一切似乎都可以正常工作,以建立索引頁(它已耗盡/ public /子目錄)。

但是,當我嘗試添加一個模塊(在這種情況下,稱為“用戶”,帶有一個名為“索引”的控制器)並按照說明進行配置時,我不確定應該在URI中放入什么以使其路由到視圖。 我已經嘗試了幾乎所有可以想到的URI組合配置( localhost:80/public/userslocalhost:80/public/users/indexlocalhost:80/users等)

我沒有路由錯誤,而只是一個普通的404頁面。

我是否需要將公用文件夾設置為根目錄? 還是我需要做一些其他事情才能使路由正常工作?

〜編輯以響應bitWorking

看起來它確實會自動將其添加到application.config.php中。 但是這里是用戶模塊的module.config.php

'router' => array(
    'routes' => array(
        'users' => array(
            'type'    => 'Literal',
            'options' => array(
                // Change this to something specific to your module
                'route'    => '/index',
                'defaults' => array(
                    // Change this value to reflect the namespace in which
                    // the controllers for your module are found
                    '__NAMESPACE__' => 'Users\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                // This route is a sane default when developing a module;
                // as you solidify the routes for your module, however,
                // you may want to remove it and replace it with more
                // specific routes.
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),
            ),
        ),
    ),
),

現在,我確實看到它在指導您自定義路線。 我也對此進行了嘗試,但仍不確定應將其設置為什么。 雖然更近了。

如果要使用/users在Users模塊中調用Index控制器,則必須相應地命名路由:

...
'users' => array(
    'type'    => 'Literal',
    'options' => array(
        // Change this to something specific to your module
        'route'    => '/users',
                      ---------
        ...

否則,請控制application.config.php 它應該看起來像:

return array(
    'modules' => array(
        'Application',
        'Users',
    ),
    ...

因此,網址應如下所示:

localhost/public/users -> Users/Controller/IndexController/indexAction
localhost/public/users/foo -> Users/Controller/FooController/indexAction
localhost/public/users/foo/bar -> Users/Controller/FooController/barAction

暫無
暫無

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

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