Php Zend Framework中模块的URI路由有问题
我刚开始使用Zend框架,我不太确定URI路由有什么问题 我从Zend Studio中的一个初始Zend Framework项目开始,该项目位于我的htdocs文件夹中(我在Windows 7上也使用Zend Server)。到目前为止,一切似乎都在正常工作,索引页正在运行(它的/public/子目录已经用完了) 但是,当我尝试添加一个模块时,在本例中,名为Users,带有一个名为Index的控制器,并按照配置该模块的说明进行操作,我不确定应该在URI中添加什么以使其路由到它的视图。我已经尝试了我能想到的几乎所有URI组合的配置(Php Zend Framework中模块的URI路由有问题,php,zend-framework,zend-framework2,zend-studio,zend-server,Php,Zend Framework,Zend Framework2,Zend Studio,Zend Server,我刚开始使用Zend框架,我不太确定URI路由有什么问题 我从Zend Studio中的一个初始Zend Framework项目开始,该项目位于我的htdocs文件夹中(我在Windows 7上也使用Zend Server)。到目前为止,一切似乎都在正常工作,索引页正在运行(它的/public/子目录已经用完了) 但是,当我尝试添加一个模块时,在本例中,名为Users,带有一个名为Index的控制器,并按照配置该模块的说明进行操作,我不确定应该在URI中添加什么以使其路由到它的视图。我已经尝试了
localhost:80/public/users
,localhost:80/public/users/index
,localhost:80/users
,等等)
我没有收到路由错误,只是一个普通的404页面
是否需要将公用文件夹设置为根目录?或者我还需要做些什么才能让路线正常运行
~编辑以响应bitWorking
看起来它确实会自动将其添加到application.config.php中。但是这里是Users模块的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' => 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
因此,Url应该如下所示:
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
您已将模块添加到
应用程序.config.php
?否则,请从module.config.php
发布路由。我最终实现了这一点,但只是在切换到XAMPP以运行我的本地主机而不是Zend服务器之后。在Zend服务器上,我一直得到404个页面,好像它甚至没有尝试路由URI一样。我不确定我的配置是否有问题。