Zend_Application-AvailableResources-Modules.xml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.application.available-resources.modules">
  4. <title>Zend_Application_Resource_Modules</title>
  5. <para>
  6. <classname>Zend_Application_Resource_Modules</classname> is used to initialize
  7. your application modules. If your module has a
  8. <filename>Bootstrap.php</filename> file in its root, and it contains a class
  9. named <classname>Module_Bootstrap</classname> (where "Module" is the module name),
  10. then it will use that class to bootstrap the module.
  11. </para>
  12. <para>
  13. By default, an instance of
  14. <classname>Zend_Application_Module_Autoloader</classname> will be created for the
  15. module, using the module name and directory to initialize it.
  16. </para>
  17. <para>
  18. Since the Modules resource does not take any arguments by default, in order to enable it
  19. via configuration, you need to create it as an empty array. In INI style configuration,
  20. this looks like:
  21. </para>
  22. <programlisting language="ini"><![CDATA[
  23. resources.modules[] =
  24. ]]></programlisting>
  25. <para>
  26. In XML style configuration, this looks like:
  27. </para>
  28. <programlisting language="xml"><![CDATA[
  29. <resources>
  30. <modules>
  31. <!-- Placeholder to ensure an array is created
  32. <placeholder />
  33. </modules>
  34. </resources>
  35. ]]></programlisting>
  36. <para>
  37. Using a standard PHP array, simply create it as an empty array:
  38. </para>
  39. <programlisting language="php"><![CDATA[
  40. $options = array(
  41. 'resources' => array(
  42. 'modules' => array(),
  43. ),
  44. );
  45. ]]></programlisting>
  46. <note>
  47. <title>Front Controller Resource Dependency</title>
  48. <para>
  49. The Modules resource has a dependency on the <link
  50. linkend="zend.application.available-resources.frontcontroller">Front
  51. Controller resource</link>. You can, of course, provide your own
  52. replacement for that resource via a custom Front Controller resource
  53. class or a class initializer method -- so long as the resource
  54. plugin class ends in "Frontcontroller" or the initializer method is
  55. named "_initFrontController" (case insensitive).
  56. </para>
  57. </note>
  58. <example id="zend.application.available-resources.modules.configExample">
  59. <title>Configuring Modules</title>
  60. <para>
  61. You can specify module-specific configuration using the module name
  62. as a prefix or sub-section in your configuration file.
  63. </para>
  64. <para>
  65. For example, let's assume that your application has a "news" module.
  66. The following are <acronym>INI</acronym> and <acronym>XML</acronym> examples showing
  67. configuration of resources in that module.
  68. </para>
  69. <programlisting language="ini"><![CDATA[
  70. [production]
  71. news.resources.db.adapter = "pdo_mysql"
  72. news.resources.db.params.host = "localhost"
  73. news.resources.db.params.username = "webuser"
  74. news.resources.db.params.password = "XXXXXXX"
  75. news.resources.db.params.dbname = "news"
  76. ]]></programlisting>
  77. <programlisting language="xml"><![CDATA[
  78. <?xml version="1.0"?>
  79. <config>
  80. <production>
  81. <news>
  82. <resources>
  83. <db>
  84. <adapter>pdo_mysql</adapter>
  85. <params>
  86. <host>localhost</host>
  87. <username>webuser</username>
  88. <password>XXXXXXX</password>
  89. <dbname>news</dbname>
  90. </params>
  91. <isDefaultAdapter>true</isDefaultAdapter>
  92. </db>
  93. </resources>
  94. </news>
  95. </production>
  96. </config>
  97. ]]></programlisting>
  98. </example>
  99. <example id="zend.application.available-resources.modules.retrieveBootstrapExample">
  100. <title>Retrieving a specific module bootstrap</title>
  101. <para>
  102. On occasion, you may need to retrieve the bootstrap object for a
  103. specific module -- perhaps to run discrete bootstrap methods, or to
  104. fetch the autoloader in order to configure it. This can be done
  105. using the Modules resource's <methodname>getExecutedBootstraps()</methodname>
  106. method.
  107. </para>
  108. <programlisting language="php"><![CDATA[
  109. $resource = $bootstrap->getPluginResource('modules');
  110. $moduleBootstraps = $resource->getExecutedBootstraps();
  111. $newsBootstrap = $moduleBootstraps['news'];
  112. ]]></programlisting>
  113. </example>
  114. </sect2>