| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?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>
|