2014-10-29 48 views
0

我剛剛開始使用Zend Framework,並且我不太確定我在做什麼錯誤的URI路由。Zend Framework中的模塊URI路由問題

我開始在基於我的htdocs文件夾(我在Windows 7上使用Zend服務器)的Zend Studio中初始Zend Framework項目。到目前爲止,一切似乎正在工作得很好,索引頁面(超出了/ public /子目錄)。

但是,當我嘗試添加一個模塊,雖然在這種情況下稱爲具有控制器的用戶稱爲索引,並按照獲取配置的說明,我不知道我應該放在URI中以獲得它路由到它的視圖。我已經嘗試了幾乎所有可以想到的URI組合配置(localhost:80/public/users,localhost:80/public/users/index,localhost:80/users等)

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

我是否需要將公用文件夾設置爲根?還是有什麼我需要做的路線工作?

〜編輯迴應bitWorking

它看起來像它會自動將其添加到application.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(
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
), 

現在我確實看到它指導您定製路線。我也嘗試過這一點,但仍然不確定我應該如何設置它們。儘管更接近。

+0

您已經添加模塊到'application.config.php'?否則請從'module.config.php'發佈路由.. – bitWorking 2014-10-29 17:48:19

回答

1

如果你想與/users調用索引控制器用戶模塊必須相應地命名路線:

... 
'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', 
    ), 
    ... 

所以URL的應該是這樣的:

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

我最終得到了這個工作,但只有在切換到XAMPP才能運行本地主機而不是Zend Server之後。使用Zend服務器,我一直收到404頁,因爲它甚至沒有嘗試路由URI。我不確定在配置中是否有問題。 – cchapman 2014-10-31 20:51:44