Zend_Application-AvailableResources-Frontcontroller.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.application.available-resources.frontcontroller">
  4. <title>Zend_Application_Resource_Frontcontroller</title>
  5. <para>
  6. Probably the most common resource you will load with
  7. <classname>Zend_Application</classname> will be the Front Controller resource,
  8. which provides the ability to configure
  9. <classname>Zend_Controller_Front</classname>. This resource provides the ability
  10. to set arbitrary front controller parameters, specify plugins to
  11. initialize, and much more.
  12. </para>
  13. <para>
  14. Once initialized, the resource assigns the <varname>$frontController</varname>
  15. property of the bootstrap to the <classname>Zend_Controller_Front</classname>
  16. instance.
  17. </para>
  18. <para>
  19. Available configuration keys include the following, and are case
  20. insensitive:
  21. </para>
  22. <itemizedlist>
  23. <listitem>
  24. <para>
  25. <emphasis><property>controllerDirectory</property></emphasis>: either a string value
  26. specifying a single controller directory, or an array of
  27. module to controller directory pairs.
  28. </para>
  29. </listitem>
  30. <listitem>
  31. <para>
  32. <emphasis><property>moduleControllerDirectoryName</property></emphasis>: a string
  33. value indicating the subdirectory under a module that contains controllers.
  34. </para>
  35. </listitem>
  36. <listitem>
  37. <para>
  38. <emphasis><property>moduleDirectory</property></emphasis>: directory under which
  39. modules may be found.
  40. </para>
  41. </listitem>
  42. <listitem>
  43. <para>
  44. <emphasis><property>defaultControllerName</property></emphasis>: base name of the
  45. default controller (normally "index").
  46. </para>
  47. </listitem>
  48. <listitem>
  49. <para>
  50. <emphasis><property>defaultAction</property></emphasis>: base name of the default
  51. action (normally "index").
  52. </para>
  53. </listitem>
  54. <listitem>
  55. <para>
  56. <emphasis><property>defaultModule</property></emphasis>: base name of the default
  57. module (normally "default").
  58. </para>
  59. </listitem>
  60. <listitem>
  61. <para>
  62. <emphasis><property>baseUrl</property></emphasis>: explicit base
  63. <acronym>URL</acronym> to the application (normally auto-detected).
  64. </para>
  65. </listitem>
  66. <listitem>
  67. <para>
  68. <emphasis><property>plugins</property></emphasis>: array of front controller plugin
  69. class names. The resource will instantiate each class (with no constructor
  70. arguments) and then register the instance with the front controller. If you want to
  71. register a plugin with a particular stack index, you need to provide an array with
  72. two keys <property>class</property> and <property>stackIndex</property>.
  73. </para>
  74. </listitem>
  75. <listitem>
  76. <para>
  77. <emphasis><property>params</property></emphasis>: array of key to value pairs to
  78. register with the front controller.
  79. </para>
  80. </listitem>
  81. <listitem>
  82. <para>
  83. <emphasis><property>returnresponse</property></emphasis>: whether or not to return
  84. the response object after dispatching the front controller. Value should be a
  85. boolean; by default, this is disabled.
  86. </para>
  87. </listitem>
  88. <listitem>
  89. <para>
  90. <emphasis><property>dispatcher</property></emphasis>: allows overriding the default
  91. dispatcher. Has two subkeys, <property>class</property> (the classname of new dispatcher)
  92. and <property>params</property>, an array of parameters to pass to the dispatcher constructor.
  93. </para>
  94. <example id="zend.application.available-resources.frontcontroller.configExample">
  95. <title>Overriding the dispatcher</title>
  96. <programlisting language="ini"><![CDATA[
  97. [production]
  98. resources.frontController.dispatcher.class = "My_Custom_Dispatcher"
  99. resources.frontController.dispatcher.params.foo = "bar"
  100. resources.frontController.dispatcher.params.baz = "grok"
  101. ]]></programlisting>
  102. </example>
  103. </listitem>
  104. </itemizedlist>
  105. <para>
  106. If an unrecognized key is provided, it is registered as a front
  107. controller parameter by passing it to <methodname>setParam()</methodname>.
  108. </para>
  109. <example id="zend.application.available-resources.frontcontroller.configExample">
  110. <title>Sample Front Controller resource configuration</title>
  111. <para>
  112. Below is a sample <acronym>INI</acronym> snippet showing how to configure the front
  113. controller resource.
  114. </para>
  115. <programlisting language="ini"><![CDATA[
  116. [production]
  117. resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
  118. resources.frontController.moduleControllerDirectoryName = "actions"
  119. resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
  120. resources.frontController.defaultControllerName = "site"
  121. resources.frontController.defaultAction = "home"
  122. resources.frontController.defaultModule = "static"
  123. resources.frontController.baseUrl = "/subdir"
  124. resources.frontController.plugins.foo = "My_Plugin_Foo"
  125. resources.frontController.plugins.bar = "My_Plugin_Bar"
  126. resources.frontController.plugins.baz.class = "My_Plugin_Baz"
  127. resources.frontController.plugins.baz.stackIndex = 123
  128. resources.frontController.returnresponse = 1
  129. resources.frontController.env = APPLICATION_ENV
  130. ; The following proxies to:
  131. ; Zend_Controller_Action_HelperBroker::addPath('Helper_Path', $helperPrefix);
  132. resources.frontController.actionHelperPaths.HELPER_Prefix = "My/Helper/Path"
  133. ]]></programlisting>
  134. </example>
  135. <example id="zend.application.available-resources.frontcontroller.propertyExample">
  136. <title>Retrieving the Front Controller in your bootstrap</title>
  137. <para>
  138. Once your Front Controller resource has been initialized, you can
  139. fetch the Front Controller instance via the
  140. <varname>$frontController</varname> property of your bootstrap.
  141. </para>
  142. <programlisting language="php"><![CDATA[
  143. $bootstrap->bootstrap('frontController');
  144. $front = $bootstrap->frontController;
  145. ]]></programlisting>
  146. </example>
  147. </sect2>