2013-03-31 88 views
1

我一直在关注Zend的教程(http://www.youtube.com/watch?feature=player_embedded&v=EerB9bTvqrY),但是当我在项目中添加一个新模块时,我无法导航到它,本教程中的说明是否不正确?在Zend Studio中创建新模块(Zend Framework 2)

基本上,当我在Zend Studio中添加一个新模块到我的Zend Framework项目中时,我无法导航到它,我的新模块被称为“交易”。我导航到本地主机/ dealproject /交易,我得到错误404。当浏览到本地主机/ dealproject /它正确加载zend骨架应用程序页面。

感谢您的帮助。

module.config.php

<?php 
return array(
'controllers' => array(
    'invokables' => array(
     'Deals\Controller\Deals' => 'Deals\Controller\DealsController', 
    ), 
), 
'router' => array(
    'routes' => array(
     'deals' => array(
      'type' => 'Literal', 
      'options' => array(
       // Change this to something specific to your module 
       'route' => '/deals', 
       'defaults' => array(
        // Change this value to reflect the namespace in which 
        // the controllers for your module are found 
        '__NAMESPACE__' => 'Deals\Controller', 
        'controller' => 'Deals', 
        '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(
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
), 
'view_manager' => array(
    'template_path_stack' => array(
     'Deals' => __DIR__ . '/../view', 
    ), 
), 

);

+0

能否请你告诉我们,从导致问题:) –

+0

现在我已经发布module.config.php模块的module.config.php你的路由配置在问题中。谢谢你的帮助。 – Jonjon

+0

谢谢,它看起来不错:)。我发布了一个答案,希望它能帮助你解决你的404错误:) –

回答

0

对我来说,路由配置看起来是正确的,它应该显示结果。我注意到,ZF2应用程序的基本URL(localhost/dealproject/)位于域根目录的子目录中。正如您可能知道所有请求都映射到应用程序的index.php(~/public/index.php)。这是通过.htaccess文件中的某些配置完成的(在同一目录中)。

在示例网址www.example.com/blog中,如果blog不存在作为www.example.com根目录下的文件夹,则会得到404 Page not found。但是,如果没有找到目录(假定您使用ZendSkeletonApplication),则ZF2的.htaccess会使apache在域的根目录中调用index.php。现在

,因为你的index.php不在域根(localhost/),但在localhost/dealproject/和你的.htaccess是(我认为)在localhost/dealproject/还有,当你打电话,因为在localhost/dealproject/deals Apache是​​寻找一个目录dealproject/dealslocalhost没有.htaccess来准备必要的配置。

我建议您将dealproject文件夹作为localhost的根目录。这将使您能够像这样呼叫您的路线:localhost/deals并且.htaccess和index.php将被正确处理。

希望这有助于:)

斯托扬

1

确保您已启用模块~/config/application.config.php

'modules' => array(
    'Application', 
    'Deals', 
), 
+0

模块已启用,当我创建模块时,Zend Studio将它添加到application.config.php中。据我所知,一切都是正确的,Zend Studio安装有问题吗? – Jonjon