PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/en/appendices/2-1-migration-guide.rst

https://gitlab.com/albertkeba/docs
ReStructuredText | 363 lines | 268 code | 95 blank | 0 comment | 0 complexity | 2b20fd6cd5f4845d55f11f662d6a1745 MD5 | raw file
  1. 2.1 Migration Guide
  2. ###################
  3. CakePHP 2.1 is a fully API compatible upgrade from 2.0. This page outlines the
  4. changes and improvements made for 2.1.
  5. AppController, AppHelper, AppModel and AppShell
  6. ===============================================
  7. These classes are now required to be part of the app directory, as they were
  8. removed from the CakePHP core. If you do not already have these classes, you
  9. can use the following while upgrading::
  10. // app/View/Helper/AppHelper.php
  11. App::uses('Helper', 'View');
  12. class AppHelper extends Helper {
  13. }
  14. // app/Model/AppModel.php
  15. App::uses('Model', 'Model');
  16. class AppModel extends Model {
  17. }
  18. // app/Controller/AppController.php
  19. App::uses('Controller', 'Controller');
  20. class AppController extends Controller {
  21. }
  22. // app/Console/Command/AppShell.php
  23. App::uses('Shell', 'Console');
  24. class AppShell extends Shell {
  25. }
  26. If your application already has these files/classes you don't need to do
  27. anything.
  28. Additionally if you were using the core PagesController, you would need to copy
  29. this to your app/Controller directory as well.
  30. .htaccess files
  31. ===============
  32. The default ``.htaccess`` files have changed, you should remember to update them
  33. or update your webservers URL re-writing scheme to match the changes done in
  34. ``.htaccess``
  35. Models
  36. ======
  37. - The ``beforeDelete`` callback will be fired before behaviors beforeDelete callbacks.
  38. This makes it consistent with the rest of the events triggered in the model layer.
  39. - ``Model::find('threaded')`` now accepts ``$options['parent']`` if using other field
  40. then ``parent_id``. Also if the model has TreeBehavior attached and set up with other
  41. parent field, the threaded find will by default use that.
  42. - Parameters for queries using prepared statements will now be part of the SQL
  43. dump.
  44. - Validation arrays can now be more specific with when a field is required.
  45. The ``required`` key now accepts ``create`` and ``update``. These values will
  46. make a field required when creating or updating.
  47. - Model now has a ``schemaName`` property. If your application switches
  48. datasources by modifying :php:attr:`Model::$useDbConfig` you should also
  49. modify ``schemaName`` or use :php:meth:`Model::setDataSource()` method which
  50. handles this for you.
  51. CakeSession
  52. -----------
  53. .. versionchanged:: 2.1.1
  54. CakeSession no longer sets the P3P header, as this is the responsibility of your application.
  55. More info see ticket `#2515 <http://cakephp.lighthouseapp.com/projects/42648/tickets/2515-cakephp-20-session-p3p-header-doesnt-work-in-an-iframe>`_ in lighthouse
  56. Behaviors
  57. =========
  58. TranslateBehavior
  59. -----------------
  60. - :php:class:`I18nModel` has been moved into a separate file.
  61. Exceptions
  62. ==========
  63. The default exception rendering now includes more detailed stack traces
  64. including file excerpts and argument dumps for all functions in the stack.
  65. Utility
  66. =======
  67. Debugger
  68. --------
  69. - :php:func:`Debugger::getType()` has been added. It can be used to get the type of
  70. variables.
  71. - :php:func:`Debugger::exportVar()` has been modified to create more readable
  72. and useful output.
  73. debug()
  74. -------
  75. `debug()` now uses :php:class:`Debugger` internally. This makes it consistent
  76. with Debugger, and takes advantage of improvements made there.
  77. Set
  78. ---
  79. - :php:func:`Set::nest()` has been added. It takes in a flat array and returns a nested array
  80. File
  81. ----
  82. - :php:meth:`File::info()` includes filesize & mimetype information.
  83. - :php:meth:`File::mime()` was added.
  84. Cache
  85. -----
  86. - :php:class:`CacheEngine` has been moved into a separate file.
  87. Configure
  88. ---------
  89. - :php:class:`ConfigReaderInterface` has been moved into a separate file.
  90. App
  91. ---
  92. - :php:meth:`App::build()` now has the ability to register new packages using
  93. ``App::REGISTER``. See :ref:`app-build-register` for more information.
  94. - Classes that could not be found on configured paths will be searched inside
  95. ``APP`` as a fallback path. This makes autoloading nested directories in
  96. ``app/Vendor`` easier.
  97. Console
  98. =======
  99. Test Shell
  100. ----------
  101. A new TestShell has been added. It reduces the typing required to run unit
  102. tests, and offers a file path based UI::
  103. ./Console/cake test app Model/Post
  104. ./Console/cake test app Controller/PostsController
  105. ./Console/cake test Plugin View/Helper/MyHelper
  106. The old testsuite shell and its syntax are still available.
  107. General
  108. -------
  109. - Generated files no longer contain timestamps with the generation datetime.
  110. Routing
  111. =======
  112. Router
  113. ------
  114. - Routes can now use a special ``/**`` syntax to include all trailing arguments
  115. as a single passed argument. See the section on :ref:`connecting-routes` for
  116. more information.
  117. - :php:meth:`Router::resourceMap()` was added.
  118. - :php:meth:`Router::defaultRouteClass()` was added. This method allows you to
  119. set the default route class used for all future routes that are connected.
  120. Network
  121. =======
  122. CakeRequest
  123. -----------
  124. - Added ``is('requested')`` and ``isRequested()`` for detecting requestAction.
  125. CakeResponse
  126. ------------
  127. - Added :php:meth:`CakeResponse::cookie()` for setting cookies.
  128. - Added a number of methods for :ref:`cake-response-caching`
  129. Controller
  130. ==========
  131. Controller
  132. ----------
  133. - :php:attr:`Controller::$uses` was modified the default value is now ``true``
  134. instead of false. Additionally different values are handled slightly
  135. differently, but will behave the same in most cases.
  136. - ``true`` Will load the default model and merge with AppController.
  137. - An array will load those models and merge with AppController.
  138. - An empty array will not load any models other than those declared in the
  139. base class.
  140. - ``false`` will not load any models, and will not merge with the base class
  141. either.
  142. Components
  143. ==========
  144. AuthComponent
  145. -------------
  146. - :php:meth:`AuthComponent::allow()` no longer accepts ``allow('*')`` as a wildcard
  147. for all actions. Just use ``allow()``. This unifies the API between allow()
  148. and deny().
  149. - ``recursive`` option was added to all authentication adapters. Allows you to
  150. more easily control the associations stored in the session.
  151. AclComponent
  152. ------------
  153. - :php:class:`AclComponent` no longer lowercases and inflects the class name used for
  154. ``Acl.classname``. Instead it uses the provided value as is.
  155. - Acl backend implementations should now be put in ``Controller/Component/Acl``.
  156. - Acl implementations should be moved into the Component/Acl directory from
  157. Component. For example if your Acl class was called ``CustomAclComponent``,
  158. and was in ``Controller/Component/CustomAclComponent.php``.
  159. It should be moved into ``Controller/Component/Acl/CustomAcl.php``, and be
  160. named ``CustomAcl``.
  161. - :php:class:`DbAcl` has been moved into a separate file.
  162. - :php:class:`IniAcl` has been moved into a separate file.
  163. - :php:class:`AclInterface` has been moved into a separate file.
  164. Helpers
  165. =======
  166. TextHelper
  167. ----------
  168. - :php:meth:`TextHelper::autoLink()`, :php:meth:`TextHelper::autoLinkUrls()`,
  169. :php:meth:`TextHelper::autoLinkEmails()` now HTML escape their input by
  170. default. You can control this with the ``escape`` option.
  171. HtmlHelper
  172. ----------
  173. - :php:meth:`HtmlHelper::script()` had a ``block`` option added.
  174. - :php:meth:`HtmlHelper::scriptBlock()` had a ``block`` option added.
  175. - :php:meth:`HtmlHelper::css()` had a ``block`` option added.
  176. - :php:meth:`HtmlHelper::meta()` had a ``block`` option added.
  177. - The ``$startText`` parameter of :php:meth:`HtmlHelper::getCrumbs()` can now be
  178. an array. This gives more control and flexibility over the first crumb link.
  179. - :php:meth:`HtmlHelper::docType()` now defaults to HTML5.
  180. - :php:meth:`HtmlHelper::image()` now has a ``fullBase`` option.
  181. - :php:meth:`HtmlHelper::media()` has been added. You can use this method to
  182. create HTML5 audio/video elements.
  183. - :term:`plugin syntax` support has been added for
  184. :php:meth:`HtmlHelper::script()`, :php:meth:`HtmlHelper::css()`, :php:meth:`HtmlHelper::image()`.
  185. You can now easily link to plugin assets using ``Plugin.asset``.
  186. - :php:meth:`HtmlHelper::getCrumbList()` had the ``$startText`` parameter added.
  187. View
  188. ====
  189. - :php:attr:`View::$output` is deprecated.
  190. - ``$content_for_layout`` is deprecated. Use ``$this->fetch('content');``
  191. instead.
  192. - ``$scripts_for_layout`` is deprecated. Use the following instead::
  193. echo $this->fetch('meta');
  194. echo $this->fetch('css');
  195. echo $this->fetch('script');
  196. ``$scripts_for_layout`` is still available, but the :ref:`view blocks <view-blocks>` API
  197. gives a more extensible & flexible replacement.
  198. - The ``Plugin.view`` syntax is now available everywhere. You can use this
  199. syntax anywhere you reference the name of a view, layout or element.
  200. - The ``$options['plugin']`` option for :php:meth:`~View::element()` is
  201. deprecated. You should use ``Plugin.element_name`` instead.
  202. Content type views
  203. ------------------
  204. Two new view classes have been added to CakePHP. A new :php:class:`JsonView`
  205. and :php:class:`XmlView` allow you to easily generate XML and JSON views. You
  206. can learn more about these classes in the section on
  207. :doc:`/views/json-and-xml-views`
  208. Extending views
  209. ---------------
  210. :php:class:`View` has a new method allowing you to wrap or 'extend' a
  211. view/element/layout with another file. See the section on
  212. :ref:`extending-views` for more information on this feature.
  213. Themes
  214. ------
  215. The ``ThemeView`` class is deprecated in favor of the ``View`` class. Simply
  216. setting ``$this->theme = 'MyTheme'`` will enable theme support, and all custom
  217. View classes which extend from ``ThemeView`` should extend ``View``.
  218. View blocks
  219. -----------
  220. View blocks are a flexible way to create slots or blocks in your views. Blocks
  221. replace ``$scripts_for_layout`` with a more robust and flexible API. See the
  222. section on :ref:`view-blocks` for more information.
  223. Helpers
  224. =======
  225. New callbacks
  226. -------------
  227. Two new callbacks have been added to Helpers.
  228. :php:meth:`Helper::beforeRenderFile()` and :php:meth:`Helper::afterRenderFile()`
  229. these new callbacks are fired before/after every view fragment is rendered.
  230. This includes elements, layouts and views.
  231. CacheHelper
  232. -----------
  233. - ``<!--nocache-->`` tags now work inside elements correctly.
  234. FormHelper
  235. ----------
  236. - FormHelper now omits disabled fields from the secured fields hash. This makes
  237. working with :php:class:`SecurityComponent` and disabled inputs easier.
  238. - The ``between`` option when used in conjunction with radio inputs, now behaves
  239. differently. The ``between`` value is now placed between the legend and first
  240. input elements.
  241. - The ``hiddenField`` option with checkbox inputs can now be set to a specific
  242. value such as 'N' rather than just 0.
  243. - The ``for`` attribute for date + time inputs now reflects the first generated
  244. input. This may result in the for attribute changing for generated datetime
  245. inputs.
  246. - The ``type`` attribute for :php:meth:`FormHelper::button()` can be removed now. It still
  247. defaults to 'submit'.
  248. - :php:meth:`FormHelper::radio()` now allows you to disable all options.
  249. You can do this by setting either ``'disabled' => true`` or ``'disabled' => 'disabled'``
  250. in the ``$attributes`` array.
  251. PaginatorHelper
  252. ---------------
  253. - :php:meth:`PaginatorHelper::numbers()` now has a ``currentClass`` option.
  254. Testing
  255. =======
  256. - Web test runner now displays the PHPUnit version number.
  257. - Web test runner now defaults to displaying app tests.
  258. - Fixtures can be created in different datasources other than $test.
  259. - Models loaded using the ClassRegistry and using another datasource will get
  260. their datasource name prepended with ``test_`` (e.g datasource `master` will
  261. try to use `test_master` in the testsuite)
  262. - Test cases are generated with class specific setup methods.
  263. Events
  264. ======
  265. - A new generic events system has been built and it replaced the way callbacks
  266. were dispatched. This should not represent any change to your code.
  267. - You can dispatch your own events and attach callbacks to them at will, useful
  268. for inter-plugin communication and easier decoupling of your classes.