您的位置:首页 > 编程语言 > PHP开发

module/config/module.config.php文件内涵定义

2015-10-23 20:59 651 查看
'router' =>array(),// 路由

'controllers' =>array(),// 控制器

'view_manager' =>array(),// 视图管理器

'service_manager' =>array(),// 服务器管理器

'translator' =>array(),// 译码器或翻译器

'navigation' =>array(),// 页面导航

路径:/module/Application/config/module.config.php

内容如下:

return array(

'router' => array(

'routes' => array(

'application' => array(

'type' => 'segment',

'options' => array(

'route' => '/[application][:controller][/:action]',

'constraints' => array(

'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',

'action' => '[a-zA-Z0-9_-]*',

),

'defaults' => array(

'__NAMESPACE__' => 'Application\Controller',

'controller' => 'Index',

'action' => 'index'

),

),

),

),

),

'controllers' => array(

'invokables' => array(

'Application\Controller\Index' => 'Application\Controller\IndexController'

),

),

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

'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',

'error/404' => __DIR__ . '/../view/error/404.phtml',

'error/index' => __DIR__ . '/../view/error/index.phtml',

),

'template_path_stack' => array(

'application' => __DIR__ . '/../view'

),

),

'service_manager' => array(

'factories' => array(

'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',

'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',

),

),

'translator' => array(

'locale' => 'en_US',

'translation_file_patterns' => array(

array(

'type' => 'gettext',

'base_dir' => __DIR__ . '/../language',

'pattern' => '%s.mo',

),

),

),

'navigation' => array(

'default' => array(

array(

'label' => 'Home',

'route' => 'applicaton’

),

array(

'label' => 'Application',

'route' => 'application’,

'pages' => array(

array(

'label' => 'List',

'route' => 'application’,

'action' => 'list',

),

),

),

),

),

);

先对以上配置进行归类:

array(// 总配置

‘router’ =>array(),// 路由

‘controllers’ =>array(),// 控制器

‘view_manager’ =>array(),// 视图管理器

‘service_manager’ =>array(),// 服务器管理器

‘translator’ =>array(),// 译码器或翻译器

‘navigation’ =>array(),// 页面导航

);

下面对 router、controllers、view_manager、service_manager、translator 、navigation进行逐个解释。

3.2.1 router 路由配置

路由的配置是对前台页面访问地址的具体配置,此处配置的格式将影响到前台页面访问此模块的所有地址

链:router--->routes--->模块--->具体配置

lrouter 此数组块为路由配置信息段

lrouter-->routes 表示此模块的中路由,路由至少1条以上

lrouter-->routes-->application 表示你的模块名称,在此以下的信息为具体配置信息

lrouter-->routes-->application-->type 表示路由模式,可选 segment 或 literal,区别在于 segment 已经处理好了结尾的斜杠,而literal 会把结尾带与不带斜杠表示不同的路由进行处理; 如果使用literal 时需要特别注意这一点。

lrouter-->routes-->application-->options 路由具体选项信息区块

lrouter-->roytes-->application-->options-->route 路由规则,此处规则将最终决定此模块的路由访问格式

lrouter-->roytes-->application-->options-->constraints 路由匹配规则

lrouter-->roytes-->application-->options-->constraints-->controller 控制器的路由正规匹配规则

lrouter-->roytes-->application-->options-->constraints-->action action(动作)的路由正规匹配规则

lrouter-->roytes-->application-->options-->defaults 默认路由处理规则

lrouter-->roytes-->application-->options-->defaults-->__NAMESPACE__ 指定模块控制器所在的命名空间

lrouter-->roytes-->application-->options-->defaults-->controller 指定默认使用的控制器名称

lrouter-->roytes-->application-->options-->defaults-->action 指定默认使用的action(动作)名称

3.2.2 controllers控制器配置

控制器的配置将决定哪些控制器类能够被访问及使用,在此配置后ZF2自动加载厂可以很快的定位到控制所在的位置,对资源进行快速访问、使用。

链:controllers--->invokables--->控制器

lcontrollers 表示此数组块为控制器配置信息段

lcontrollers-->invokables 这个是控制器区块的固定表示方法,表示此区块下的控制器为可用控制器

lcontrollers-->invokables-->Application\Controller\Index 表示一个控制器,数组的键表示DI注入的引用,数组值则表示对应控制器所在的具体路径

控制器的配置不局限于某一个控制器,可以把所有已经存在并且有效控制器加入到此区块来进行使用。

3.2.3 view_manager 视图管理器

视图管理器主要负责视图信息的配置,如:错误显示、页面类型、布局文件、视图文件位置、404页面等。

链:view_manager-->N , view_manager-->template_map , view_manager-->template_path_stack

lview_manager 表示此数组块为视图管理器配置信息段

lview_manager-->display_not_found_reason 是否显示404原因

lview_manager-->display_exceptions 是否显示异常信息

lview_manager-->doctype 指定视图页面类型

lview_manager-->not_found_template 指定404的视图模板

lview_manager-->exception_template 指定异常模板文件

lview_manager-->template_map 视图模块地图

lview_manager-->template_map-->’layout/layout’ 指定布局文件

lview_manager-->template_map-->’application/index/index’ 指定 application 模块的视图文件

lview_manager-->template_map-->’error/404’ 指定404页面的视图文件

lview_manager-->template_map-->’error/index’ 指定错误异常页面的视图文件

lview_manager-->template_path_stack 视图模板堆栈路径

lview_manager-->template_path_stack-->application 指定模块application 视图目录所在路径

3.2.4 service_manager 服务管理器

服务管理器主要负责一些工厂类的配置,使用系统能够在运行时自动的加载运行某些服务性功能。

链:service_manager-->factories

lservice_manager 表示此数组块为服务管理器配置信息段

lservice_manager-->factories 工厂类配置

lservice_manager-->factories-->translator 语言转换工厂,主要功能是实现多国语言的支持,语言文件需要自已编写;ZF2框架本身并不提供语言包,但提供对语言包的解析功能,通过语言包通过指定的语言进行转换;同时语言之间的转换及格式的变化比较而随意性也比较大,所以语言包可以根据项目的实现需求来进行订制,如果实际的项目开发中并不使用到国际化的功能时,可以将多国语言国际功能删除。

lservice_manager-->factories-->translator-->navigation 导航工厂,主要用来实现页面的导航和分页导航

3.2.5 translator 翻译器

翻译器的主要工作是负责对各种支持语言的转换以此为目的,从而实现网站应用程序的多国化甚至全球化。本书内容有涉及到使用语言包,语言包的生成可以参考po,mo 文件创建的其他文献;你也可以通过 Zend Studio 来创建项目以获取ZF2 默认生成的language 包。下面将会提供两个语言包内容 zh_CN.po ,en_US.po 这个为中英文件互转文件,这两语言由Zend Studio项目生成时自动创建;他们对应的mo文件可以通过 poedit 软件来生成,也可能过poedit 来修改po文件。如果在开发时不想使用任何语言转换,可以不进行任何关于语言转换相关的配置。

链:translator-->locale , translator-->translation_file_patterns

ltranslator 表示此数组块为翻译器配置信息段

ltranslator-->locale 指明应用程序的本地使用语言,或是应用程序使用的默认语言

ltranslator-->translation_file_patterns 翻译文件的配置设置

ltranslator-->translation_file_patterns-->type 翻译文件类型

ltranslator-->translation_file_patterns-->base_dir 指定语言文件目录

ltranslator-->translation_file_patterns-->pattern 语言文件的匹配规则

下面提供两个语言包,语言包为中英语言包,可以在开发的时候对两种语言环境进行切换。

3.2.5.1 语言文件 zh_CN.po 内容

msgid ""

msgstr ""

"Project-Id-Version: ZendSkeletonApplication\n"

"Report-Msgid-Bugs-To: \n"

"POT-Creation-Date: 2012-07-05 22:17-0700\n"

"PO-Revision-Date: 2013-05-06 11:26+0800\n"

"Last-Translator: \n"

"Language-Team: ZF Contibutors <zf-devteam@zend.com>\n"

"Language: en_US\n"

"MIME-Version: 1.0\n"

"Content-Type: text/plain; charset=UTF-8\n"

"Content-Transfer-Encoding: 8bit\n"

"X-Poedit-KeywordsList: translate\n"

"X-Poedit-Basepath: .\n"

"X-Generator: Poedit 1.5.5\n"

"X-Poedit-SearchPath-0: ..\n"

msgid "Home"

msgstr "主页"

msgid "All rights reserved."

msgstr "版权所有."

msgid "Help & Support"

msgstr "帮助 & 支持"

msgid "An error occurred"

msgstr "发生错误"

msgid "Additional information"

msgstr "附加信息"

msgid "File"

msgstr "文件"

msgid "Message"

msgstr "消息"

msgid "Stack trace"

msgstr "Stack trace"

msgid "Previous exceptions"

msgstr "上一个异常"

msgid "No Exception available"

msgstr "没有可用的Exception"

msgid "A 404 error occurred"

msgstr "404 缺少目标文件"

msgid "The requested controller was unable to dispatch the request."

msgstr "所请求的控制器不能分发该请求"

msgid ""

"The requested controller could not be mapped to an existing controller class."

msgstr "所请求的控制器不能映射到已存在的控制器类"

msgid "The requested URL could not be matched by routing."

msgstr "所请求的URL不能与路由对应"

msgid "We cannot determine at this time why a 404 was generated."

msgstr "我们不能确定为什么这次会出现404"

msgid "Controller"

msgstr "控制器"

msgid "resolves to %s"

msgstr "解决: %s"

msgid "Exception"

msgstr "异常"

msgid "Add"

msgstr "添加"

msgid "Delete"

msgstr "删除"

msgid "Edit"

msgstr "修改"

msgid "Add new album"

msgstr "添加新闻"

msgid "Title"

msgstr "标题"

msgid "Artist"

msgstr "文章内容"

3.2.5.2 语言文件 en_US.po 内容

msgid ""

msgstr ""

"Project-Id-Version: ZendSkeletonApplication\n"

"Report-Msgid-Bugs-To: \n"

"POT-Creation-Date: 2012-07-05 22:17-0700\n"

"PO-Revision-Date: 2012-07-05 22:17-0700\n"

"Last-Translator: Evan Coury <me@evancoury.com>\n"

"Language-Team: ZF Contibutors <zf-devteam@zend.com>\n"

"Language: \n"

"MIME-Version: 1.0\n"

"Content-Type: text/plain; charset=UTF-8\n"

"Content-Transfer-Encoding: 8bit\n"

"X-Poedit-KeywordsList: translate\n"

"X-Poedit-Language: English\n"

"X-Poedit-Country: UNITED STATES\n"

"X-Poedit-Basepath: .\n"

"X-Poedit-SearchPath-0: ..\n"

#: ../view/layout/layout.phtml:6

#: ../view/layout/layout.phtml:33

msgid "Skeleton Application"

msgstr ""

#: ../view/layout/layout.phtml:36

msgid "Home"

msgstr ""

#: ../view/layout/layout.phtml:50

msgid "All rights reserved."

msgstr ""

#: ../view/application/index/index.phtml:2

#, php-format

msgid "Welcome to %sZend Framework 2%s"

msgstr ""

#: ../view/application/index/index.phtml:3

#, php-format

msgid "Congratulations! You have successfully installed the %sZF2 Skeleton Application%s. You are currently running Zend Framework version %s. This skeleton can serve as a simple starting point for you to begin building your application on ZF2."

msgstr ""

#: ../view/application/index/index.phtml:4

msgid "Fork Zend Framework 2 on GitHub"

msgstr ""

#: ../view/application/index/index.phtml:10

msgid "Follow Development"

msgstr ""

#: ../view/application/index/index.phtml:11

#, php-format

msgid "Zend Framework 2 is under active development. If you are interested in following the development of ZF2, there is a special ZF2 portal on the official Zend Framework website which provides links to the ZF2 %swiki%s, %sdev blog%s, %sissue tracker%s, and much more. This is a great resource for staying up to date with the latest developments!"

msgstr ""

#: ../view/application/index/index.phtml:12

msgid "ZF2 Development Portal"

msgstr ""

#: ../view/application/index/index.phtml:16

msgid "Discover Modules"

msgstr ""

#: ../view/application/index/index.phtml:17

#, php-format

msgid "The community is working on developing a community site to serve as a repository and gallery for ZF2 modules. The project is available %son GitHub%s. The site is currently live and currently contains a list of some of the modules already available for ZF2."

msgstr ""

#: ../view/application/index/index.phtml:18

msgid "Explore ZF2 Modules"

msgstr ""

#: ../view/application/index/index.phtml:22

msgid "Help & Support"

msgstr ""

#: ../view/application/index/index.phtml:23

#, php-format

msgid "If you need any help or support while developing with ZF2, you may reach us via IRC: %s#zftalk on Freenode%s. We'd love to hear any questions or feedback you may have regarding the beta releases. Alternatively, you may subscribe and post questions to the %smailing lists%s."

msgstr ""

#: ../view/application/index/index.phtml:24

msgid "Ping us on IRC"

msgstr ""

#: ../view/error/index.phtml:1

msgid "An error occurred"

msgstr ""

#: ../view/error/index.phtml:8

msgid "Additional information"

msgstr ""

#: ../view/error/index.phtml:11

#: ../view/error/index.phtml:35

msgid "File"

msgstr ""

#: ../view/error/index.phtml:15

#: ../view/error/index.phtml:39

msgid "Message"

msgstr ""

#: ../view/error/index.phtml:19

#: ../view/error/index.phtml:43

#: ../view/error/404.phtml:55

msgid "Stack trace"

msgstr ""

#: ../view/error/index.phtml:29

msgid "Previous exceptions"

msgstr ""

#: ../view/error/index.phtml:58

msgid "No Exception available"

msgstr ""

#: ../view/error/404.phtml:1

msgid "A 404 error occurred"

msgstr ""

#: ../view/error/404.phtml:10

msgid "The requested controller was unable to dispatch the request."

msgstr ""

#: ../view/error/404.phtml:13

msgid "The requested controller could not be mapped to an existing controller class."

msgstr ""

#: ../view/error/404.phtml:16

msgid "The requested controller was not dispatchable."

msgstr ""

#: ../view/error/404.phtml:19

msgid "The requested URL could not be matched by routing."

msgstr ""

#: ../view/error/404.phtml:22

msgid "We cannot determine at this time why a 404 was generated."

msgstr ""

#: ../view/error/404.phtml:34

msgid "Controller"

msgstr ""

#: ../view/error/404.phtml:41

#, php-format

msgid "resolves to %s"

msgstr ""

#: ../view/error/404.phtml:51

msgid "Exception"

msgstr ""

3.2.6 navigation 导航条

导航条的主要功能是生成页面导航或分页导航

链:navigation-->N

lnavigation 表示此数组块为页面导航配置信息段

lnavigation-->default 默认页面导航

lnavigation-->default-->array() 一个导航标签配置

lnavigation-->default-->label 导航的标签

lnavigation-->default-->route 导航的路由,其实就是指向的控制器

通过以上对路由、控制器、视图、服务等各项功能的配置之后,现在已经可以通过 http://localhost/http://localhost/index/index 的链接来访问我们的操控了。通过 http://localhost/ 访问就能看到屏幕打印出 hello world ,你会发现这个链接即没有控制器也没有动作(action),怎么就可以输出内容了呢,其实通过上面的路由配置,已经设置一个默认的路由,默认路由规则中规定了默认使用的控制器为IndexController,默认访问的动作为indexAction;而 http://localhost/index/index 也是同样因为路由设置,同时该连接符合路由规则,因此同样达到了打印输出 hello world 的效果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: