migration-15.xml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="migration.15">
  4. <title>Zend Framework 1.5</title>
  5. <para>
  6. When upgrading from a previous release to Zend Framework 1.5 or higher you
  7. should note the following migration notes.
  8. </para>
  9. <sect2 id="migration.15.zend.controller">
  10. <title>Zend_Controller</title>
  11. <para>
  12. Though most basic functionality remains the same, and all documented
  13. functionality remains the same, there is one particular
  14. <emphasis>undocumented</emphasis> "feature" that has changed.
  15. </para>
  16. <para>
  17. When writing <acronym>URL</acronym>s, the documented way to write camelCased action
  18. names is to use a word separator; these are '.' or '-' by default,
  19. but may be configured in the dispatcher. The dispatcher internally
  20. lowercases the action name, and uses these word separators to
  21. re-assemble the action method using camelCasing. However, because <acronym>PHP</acronym>
  22. functions are not case sensitive, you <emphasis>could</emphasis>
  23. still write <acronym>URL</acronym>s using camelCasing, and the dispatcher would resolve
  24. these to the same location. For example, 'camel-cased' would become
  25. 'camelCasedAction' by the dispatcher, whereas 'camelCased' would
  26. become 'camelcasedAction'; however, due to the case insensitivity of
  27. <acronym>PHP</acronym>, both will execute the same method.
  28. </para>
  29. <para>
  30. This causes issues with the ViewRenderer when resolving view
  31. scripts. The canonical, documented way is that all word separators
  32. are converted to dashes, and the words lowercased. This creates
  33. a semantic tie between the actions and view scripts, and the
  34. normalization ensures that the scripts can be found. However, if the
  35. action 'camelCased' is called and actually resolves, the word
  36. separator is no longer present, and the ViewRenderer attempts to
  37. resolve to a different location -- <filename>camelcased.phtml</filename> instead of
  38. <filename>camel-cased.phtml</filename>.
  39. </para>
  40. <para>
  41. Some developers relied on this "feature", which was never intended.
  42. Several changes in the 1.5.0 tree, however, made it so that the
  43. ViewRenderer no longer resolves these paths; the semantic tie is now
  44. enforced. First among these, the dispatcher now enforces case
  45. sensitivity in action names. What this means is that referring to
  46. your actions on the url using camelCasing will no longer resolve to
  47. the same method as using word separators (i.e., 'camel-casing').
  48. This leads to the ViewRenderer now only honoring the word-separated
  49. actions when resolving view scripts.
  50. </para>
  51. <para>
  52. If you find that you were relying on this "feature", you have several
  53. options:
  54. </para>
  55. <itemizedlist>
  56. <listitem>
  57. <para>
  58. Best option: rename your view scripts. Pros: forward
  59. compatibility. Cons: if you have many view scripts that
  60. relied on the former, unintended behavior, you will have a
  61. lot of renaming to do.
  62. </para>
  63. </listitem>
  64. <listitem>
  65. <para>
  66. Second best option: The ViewRenderer now delegates view
  67. script resolution to <classname>Zend_Filter_Inflector</classname>; you
  68. can modify the rules of the inflector to no longer separate
  69. the words of an action with a dash:
  70. </para>
  71. <programlisting language="php"><![CDATA[
  72. $viewRenderer =
  73. Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
  74. $inflector = $viewRenderer->getInflector();
  75. $inflector->setFilterRule(':action', array(
  76. new Zend_Filter_PregReplace(
  77. '#[^a-z0-9' . preg_quote(DIRECTORY_SEPARATOR, '#') . ']+#i',
  78. ''
  79. ),
  80. 'StringToLower'
  81. ));
  82. ]]></programlisting>
  83. <para>
  84. The above code will modify the inflector to no longer
  85. separate the words with dash; you may also want to remove
  86. the 'StringToLower' filter if you <emphasis>do</emphasis>
  87. want the actual view script names camelCased as well.
  88. </para>
  89. <para>
  90. If renaming your view scripts would be too tedious or time
  91. consuming, this is your best option until you can find the
  92. time to do so.
  93. </para>
  94. </listitem>
  95. <listitem>
  96. <para>
  97. Least desirable option: You can force the dispatcher to
  98. dispatch camelCased action names with a new front controller
  99. flag, <property>useCaseSensitiveActions</property>:
  100. </para>
  101. <programlisting language="php"><![CDATA[
  102. $front->setParam('useCaseSensitiveActions', true);
  103. ]]></programlisting>
  104. <para>
  105. This will allow you to use camelCasing on the url and still
  106. have it resolve to the same action as when you use word
  107. separators. However, this will mean that the original issues
  108. will cascade on through; you will likely need to use the
  109. second option above in addition to this for things to work
  110. at all reliably.
  111. </para>
  112. <para>
  113. Note, also, that usage of this flag will raise a notice that
  114. this usage is deprecated.
  115. </para>
  116. </listitem>
  117. </itemizedlist>
  118. </sect2>
  119. </sect1>
  120. <!--
  121. vim:se ts=4 sw=4 et:
  122. -->