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