需要一些关于 zend frame work 2.5 module.config.php 文件的建议
Need some suggestions for zend frame work 2.5 module.config.php file
这是我的目录结构
-> = folder
- = file
wamp/www/zf2crud
->module
->Application
->CsnUser
->config
-module.config.php
->language
- ..
->src
->CsnUser
->Controller
-UserController.php
->view
->csn-user
->user
-create.phtml
-delete.phtml
-index.phtml
-update.phtml
->error
..
->layout
..
-Module.php
我按照这个教程开发了一个模块CsnUser。 reference .its old version .so i copied module.config.php from my default folder Application folder. after that if i enter http://localhost/zf2crud/public/ my zend framework deafault home page work fine and enter http://localhost/zf2crud/public/csn-user it going my CsnUser index page it also fine. but if i enter http://localhost/zf2crud/public/csn-user/user/update/ 出现 404 错误我认为问题出在我的 module.config.php
我需要查看所有其他视图,例如更新删除创建页面如何执行此操作。
这是我的 CsnUser 配置文件。
module.config.php
namespace CsnUser;
return array(
'router' => array(
'routes' => array(
'csn_user' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/csn-user',
'defaults' => array(
'controller' => 'CsnUser\Controller\user',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'csnuser' => array(
'type' => 'Literal',
'options' => array(
'route' => '/csnuser',
'defaults' => array(
'__NAMESPACE__' => 'CsnUser\Controller',
'controller' => 'user',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'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(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'factories' => array(
'translator' => 'Zend\Mvc\Service\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
// 'CsnUser\Controller\User' => Controller\UserController::class
'CsnUser\Controller\user' => 'CsnUser\Controller\UserController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'csn-user/user/index' => __DIR__ . '/../view/csn-user/user/index.phtml',
'csn-user/user/update' => __DIR__ . '/../view/csn-user/user/update.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
1) 您应该尝试直接从 public 文件夹提供您的应用程序。你现在做 http://localhost/zf2crud/public/
它实际上应该直接服务 http://localhost/
。您可以通过配置虚拟主机轻松解决此问题。
2) 如果你问我你的路由器配置似乎有点不对劲,我会建议这样的东西,我想这就是你想要的...
return array(
'router' => array(
'routes' => array(
'csnuser' => array(
'type' => 'Literal',
'options' => array(
'route' => '/csn-user',
'defaults' => array(
'__NAMESPACE__' => 'CsnUser\Controller',
'controller' => 'user',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'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(
'action' => 'index'
)
)
)
)
)
)
)
),
这将匹配如下:
url controller action
------------------------------------------------------------------------------------
http://localhost/csn-user -> CsnUser\Controller\UserController -> index
http://localhost/csn-user/user -> CsnUser\Controller\UserController -> index
http://localhost/csn-user/user/index -> CsnUser\Controller\UserController -> index
http://localhost/csn-user/user/update -> CsnUser\Controller\UserController -> update
http://localhost/csn-user/user/delete -> CsnUser\Controller\UserController -> delete
http://localhost/csn-user/user/create -> CsnUser\Controller\UserController -> create
如果您为公司引入新的控制器:
'CsnUser\Controller\company' => 'CsnUser\Controller\CompanyController'
你可以这样搭配
url controller action
------------------------------------------------------------------------------------------
http://localhost/csn-user/company -> CsnUser\Controller\CompanyController -> index
http://localhost/csn-user/company/index -> CsnUser\Controller\CompanyController -> index
http://localhost/csn-user/company/update -> CsnUser\Controller\CompanyController -> update
http://localhost/csn-user/company/delete -> CsnUser\Controller\CompanyController -> delete
http://localhost/csn-user/company/create -> CsnUser\Controller\CompanyController -> create
3) 您也可以从路由器中移除整个 csn-user
部分。好像有点没必要。。。
return array(
'router' => array(
'routes' => array(
'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(
'__NAMESPACE__' => 'CsnUser\Controller',
'action' => 'index'
'controller' => 'user'
)
)
)
)
)
),
这将匹配如下:
url controller action
------------------------------------------------------------------------------------
http://localhost -> CsnUser\Controller\UserController -> index
http://localhost/user -> CsnUser\Controller\UserController -> index
http://localhost/user/index -> CsnUser\Controller\UserController -> index
http://localhost/user/update -> CsnUser\Controller\UserController -> update
http://localhost/user/delete -> CsnUser\Controller\UserController -> delete
http://localhost/user/create -> CsnUser\Controller\UserController -> create
如果您为公司引入新的控制器:
'CsnUser\Controller\company' => 'CsnUser\Controller\CompanyController'
你可以这样搭配
url controller action
------------------------------------------------------------------------------------------
http://localhost/company -> CsnUser\Controller\CompanyController -> index
http://localhost/company/index -> CsnUser\Controller\CompanyController -> index
http://localhost/company/update -> CsnUser\Controller\CompanyController -> update
http://localhost/company/delete -> CsnUser\Controller\CompanyController -> delete
http://localhost/company/create -> CsnUser\Controller\CompanyController -> create
这是我的目录结构
-> = folder
- = file
wamp/www/zf2crud
->module
->Application
->CsnUser
->config
-module.config.php
->language
- ..
->src
->CsnUser
->Controller
-UserController.php
->view
->csn-user
->user
-create.phtml
-delete.phtml
-index.phtml
-update.phtml
->error
..
->layout
..
-Module.php
我按照这个教程开发了一个模块CsnUser。 reference .its old version .so i copied module.config.php from my default folder Application folder. after that if i enter http://localhost/zf2crud/public/ my zend framework deafault home page work fine and enter http://localhost/zf2crud/public/csn-user it going my CsnUser index page it also fine. but if i enter http://localhost/zf2crud/public/csn-user/user/update/ 出现 404 错误我认为问题出在我的 module.config.php
我需要查看所有其他视图,例如更新删除创建页面如何执行此操作。
这是我的 CsnUser 配置文件。 module.config.php
namespace CsnUser;
return array(
'router' => array(
'routes' => array(
'csn_user' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/csn-user',
'defaults' => array(
'controller' => 'CsnUser\Controller\user',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'csnuser' => array(
'type' => 'Literal',
'options' => array(
'route' => '/csnuser',
'defaults' => array(
'__NAMESPACE__' => 'CsnUser\Controller',
'controller' => 'user',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'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(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'factories' => array(
'translator' => 'Zend\Mvc\Service\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
// 'CsnUser\Controller\User' => Controller\UserController::class
'CsnUser\Controller\user' => 'CsnUser\Controller\UserController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'csn-user/user/index' => __DIR__ . '/../view/csn-user/user/index.phtml',
'csn-user/user/update' => __DIR__ . '/../view/csn-user/user/update.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
1) 您应该尝试直接从 public 文件夹提供您的应用程序。你现在做 http://localhost/zf2crud/public/
它实际上应该直接服务 http://localhost/
。您可以通过配置虚拟主机轻松解决此问题。
2) 如果你问我你的路由器配置似乎有点不对劲,我会建议这样的东西,我想这就是你想要的...
return array(
'router' => array(
'routes' => array(
'csnuser' => array(
'type' => 'Literal',
'options' => array(
'route' => '/csn-user',
'defaults' => array(
'__NAMESPACE__' => 'CsnUser\Controller',
'controller' => 'user',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'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(
'action' => 'index'
)
)
)
)
)
)
)
),
这将匹配如下:
url controller action
------------------------------------------------------------------------------------
http://localhost/csn-user -> CsnUser\Controller\UserController -> index
http://localhost/csn-user/user -> CsnUser\Controller\UserController -> index
http://localhost/csn-user/user/index -> CsnUser\Controller\UserController -> index
http://localhost/csn-user/user/update -> CsnUser\Controller\UserController -> update
http://localhost/csn-user/user/delete -> CsnUser\Controller\UserController -> delete
http://localhost/csn-user/user/create -> CsnUser\Controller\UserController -> create
如果您为公司引入新的控制器:
'CsnUser\Controller\company' => 'CsnUser\Controller\CompanyController'
你可以这样搭配
url controller action
------------------------------------------------------------------------------------------
http://localhost/csn-user/company -> CsnUser\Controller\CompanyController -> index
http://localhost/csn-user/company/index -> CsnUser\Controller\CompanyController -> index
http://localhost/csn-user/company/update -> CsnUser\Controller\CompanyController -> update
http://localhost/csn-user/company/delete -> CsnUser\Controller\CompanyController -> delete
http://localhost/csn-user/company/create -> CsnUser\Controller\CompanyController -> create
3) 您也可以从路由器中移除整个 csn-user
部分。好像有点没必要。。。
return array(
'router' => array(
'routes' => array(
'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(
'__NAMESPACE__' => 'CsnUser\Controller',
'action' => 'index'
'controller' => 'user'
)
)
)
)
)
),
这将匹配如下:
url controller action
------------------------------------------------------------------------------------
http://localhost -> CsnUser\Controller\UserController -> index
http://localhost/user -> CsnUser\Controller\UserController -> index
http://localhost/user/index -> CsnUser\Controller\UserController -> index
http://localhost/user/update -> CsnUser\Controller\UserController -> update
http://localhost/user/delete -> CsnUser\Controller\UserController -> delete
http://localhost/user/create -> CsnUser\Controller\UserController -> create
如果您为公司引入新的控制器:
'CsnUser\Controller\company' => 'CsnUser\Controller\CompanyController'
你可以这样搭配
url controller action
------------------------------------------------------------------------------------------
http://localhost/company -> CsnUser\Controller\CompanyController -> index
http://localhost/company/index -> CsnUser\Controller\CompanyController -> index
http://localhost/company/update -> CsnUser\Controller\CompanyController -> update
http://localhost/company/delete -> CsnUser\Controller\CompanyController -> delete
http://localhost/company/create -> CsnUser\Controller\CompanyController -> create