分类: PHP

Zend Framework 2 – Modules






在看modules 之前,推荐一个youtube视屏。看过之后,你会对module有一点初步的了解

好了,现在我们就不再说,什么是module,为什么要有module这种东西了。下面整理一点,对于module我觉得可以帮助更好的理解的东西:

A module is its own PHP namespace

Modules are comprised of three key concepts:

  • The Module Autoloader – a specialized autoloader that is responsible for the locating and loading of modules’ Module classes from a variety of sources.{文件/config/application.config.php}
  • The Module Manager – takes an array of module names and fires a sequence of events for each one
  • ModuleManager Listeners – Event listeners can be attached to the module manager’s various events

记住,再加入新的module的时候,要加入  /config/application.config.php


return array(

'modules' => array(

'Application',

'Generic'       <i>// << My Generic Module</i>

),

'module_listener_options' => array(

'config_glob_paths'    => array(

'config/autoload/{,*.}{global,local}.php',

),

'module_paths' => array(

'./module',

'./vendor',

),

),

);

You can see that it has two key array keys: modules and module_listener_options. 如果的的module不在modules 和 module_listener_options arrary 里面,你的module将不会被载入。

Important functions: (module.php里面重要的method)

  • getConfig()
    • It returns an array or Traversable object that contains the environment delineated configuration for your application, you can include a number of configurations areas, such as dependency injection, routing, views and more. (将相关此module的configuration,加入到array中,配置包括view,routing, DI,相关文件信息)

public function getConfig()

{

return include __DIR__ . '/config/module.config.php';

}

  • getAutoloaderConfig()
    • This informs the Module Autoloader where to find the required classes
      • 告诉module,那里去找寻相关需要的class文件

The Remaining Module :

  • src
    • Controller – All your modules controller files with the accompanying actions
      • 各种关于module的routing逻辑
    • Form – All your form objects
      • 各种表格文件object or class
    • Model – All your database objects
      • 程序相关逻辑
  • view
    • All of your view templates, in directories that match the controller names in the module and with names that match the controller actions
    • UI 模板文件 – 与controller里面的action 匹配

 




发表评论