3.7 Migration Guide
CakePHP 3.7 is an API compatible upgrade from 3.6. This page outlines the changes and improvements made in 3.7.
To upgrade to 3.7.x run the following composer command:
bash
php composer.phar require --update-with-dependencies "cakephp/cakephp:3.7.*"Deprecations
The following is a list of deprecated methods, properties and behaviors. These features will continue to function until 4.0.0 after which they will be removed.
Cake\Form\Form::errors()is deprecated. UsegetErrors()instead.Cake\Http\Client\Response::$headersis deprecated. UsegetHeaders()orgetHeaderLine()instead.Cake\Http\Client\Response::$bodyis deprecated. UsegetStringBody()instead.Cake\Http\Client\Response::$jsonis deprecated. UsegetJson()instead.Cake\Http\Client\Response::$xmlis deprecated. UsegetXml()instead.Cake\Http\Client\Response::$cookiesis deprecated. UsegetCookies()instead.Cake\Http\Client\Response::$codeis deprecated. UsegetStatusCode()instead.Cake\Http\Client\Response::body()is deprecated. UsegetStringBody()instead.Cake\ORM\Association::className()has been deprecated. UsegetClassName()andsetClassName()instead.- Using
Cake\Database\Query::join()to read information is deprecated. Instead useQuery::clause('join'). - Using
Cake\Database\Query::from()to read information is deprecated. Instead useQuery::clause('from'). Cake\Database\Connection::logQueries()is deprecated. UseenableQueryLogging()andisQueryLoggingEnabled()instead.- The string/array parameter set for
Cake\Http\Response::withCookie()is deprecated. Instead you need to pass inCake\Http\Cookie\Cookieinstances. Cake\Validation\Validation::cc()has been renamed tocreditCard().Cake\View\ViewVarsTrait::viewOptions()is deprecated. UseviewBuilder()->setOptions()instead.Cake\View\View::$requestis protected now. UseView::getRequest()/setRequest()to access a View's request instance in other contexts.Cake\View\View::$responseis protected now. UseView::getResponse()/setResponse()to access a View's response instance in other contexts.Cake\View\View::$templatePathis protected now. UsegetTemplatePath()/setTemplatePath()instead.Cake\View\View::$templateis protected now. UsegetTemplate()/setTemplate()instead.Cake\View\View::$layoutis protected now. UsegetLayout()/setLayout()instead.Cake\View\View::$layoutPathis protected now. UsegetLayoutPath()/setLayoutPath()instead.Cake\View\View::$autoLayoutis protected now. UseenableAutoLayout()/isAutoLayoutEnabled()instead.Cake\View\View::$themeis protected now. UsegetTheme()/setTheme()instead.Cake\View\View::$subDiris protected now. UsegetSubDir()/setSubDir()instead.Cake\View\View::$pluginis protected now. UsegetPlugin()/setPlugin()instead.Cake\View\View::$nameis protected now. UsegetName()/setName()instead.Cake\View\View::$elementCacheis protected now. UsegetElementCache()/setElementCache()instead.Cake\View\View::$Blocksis protected now. Use public methods on View to interact with blocks.Cake\View\View:$helpersis protected now. Usehelpers()to interact with the HelperRegistry instead.Cake\View\View::$uuidsis deprecated and will be removed in 4.0Cake\View\View::uuid()is deprecated and will be removed in 4.0Cake\View\Cell::$templateis protected now. UseviewBuilder()->getTemplate()/setTemplate()instead.Cake\View\Cell::$pluginis protected now. UseviewBuilder()->getPlugin()/setPlugin()instead.Cake\View\Cell::$helpersis protected now. UseviewBuilder()->getHelpers()/setHelpers()instead.Cake\View\Cell::$actionis protected now.Cake\View\Cell::$argsis protected now.Cake\View\Cell::$Viewis protected now.Cake\View\Cell::$requestis protected now.Cake\View\Cell::$responseis protected now.Cake\View\ViewVarsTrait::$viewVarsis deprecated. This public property will be removed in 4.0.0. Useset()instead.Cake\Filesystem\Folder::normalizePath()is deprecated. You should usecorrectSlashFor()instead.Cake\Mailer\Email::setConfigTransport()is deprecated. UseCake\Mailer\TransportFactory::setConfig()instead.Cake\Mailer\Email::getConfigTransport()is deprecated. UseCake\Mailer\TransportFactory::getConfig()instead.Cake\Mailer\Email::configTransport()is deprecated. UseCake\Mailer\TransportFactory::getConfig()/setConfig()instead.Cake\Mailer\Email::configuredTransport()is deprecated. UseCake\Mailer\TransportFactory::configured()instead.Cake\Mailer\Email::dropTransport()is deprecated. UseCake\Mailer\TransportFactory::drop()instead.- Following view related methods of
Cake\Mailer\Emailhave been deprecated:setTemplate(),getTemplate(),setLayout(),getLayout(),setTheme(),getTheme(),setHelpers(),getHelpers(). Use the same methods through Email's view builder instead. For e.g.$email->viewBuilder()->getTemplate(). Cake\Mailer\Mailer::layout()is deprecated. Use$mailer->viewBuilder()->setLayout()instead.Helper::$themeis removed. UseView::getTheme()instead.Helper::$pluginis removed. UseView::getPlugin()instead.Helper::$fieldsetandHelper::$tagsare deprecated as they are unused.Helper::$helpersis now protected and should not be accessed from outside a helper class.Helper::$requestis removed. UseView::getRequest(),View::setRequest()instead.Cake\Core\Plugin::load()andloadAll()are deprecated. Instead you should useApplication::addPlugin().Cake\Core\Plugin::unload()is deprecated. UsePlugin::getCollection()->remove()orclear()instead.- The following properties of
Cake\Error\ExceptionRenderare now protected:$error,$controller,$templateand$method. - Using underscored fixtures names in
TestCase::$fixturesis deprecated. Use CamelCased names instead. For e.g.app.FooBar,plugin.MyPlugin.FooBar.
Soft Deprecations
The following methods, properties and features have been deprecated but will not be removed until 5.0.0:
Cake\TestSuite\ConsoleIntegrationTestCaseis deprecated. You should includeCake\TestSuite\ConsoleIntegrationTestTraitinto your test case class instead.
Behavior Changes
Cake\Database\Type\IntegerTypewill now raise an exception when values are not numeric when preparing SQL statements and converting database results to PHP types.Cake\Database\Statement\StatementDecorator::fetchAll()now returns an empty array instead offalsewhen no result is found.Cake\Database\Statement\BufferedStatementno longer inherits fromStatementDecoratorand no longer implements theIteratorAggregateinterface. Instead it directly implements theIteratorinterface to better support using statements with collections.- When marshalling data from the request into entities, the ORM will now convert non-scalar data into
nullfor boolean, integer, float, and decimal types. ExceptionRendererwill now always call handler methods for custom application exception classes. Previously, custom exception class handler methods would only be invoked in debug mode.Router::url()will now default the_methodkey toGETwhen generating URLs withRouter::url().
New Features
Cache
- The
ArrayEnginewas added. This engine provides an ephemeral in memory cache implementation. It is ideal for test suites or long running processes where you don't want persistent cache storage.
Database
Cake\Database\FunctionsBuilder::rand()was added.
Datasource
Paginatorwill now match unprefixedsortvalues in the query string to the primary model if there also exists a matching model prefixed default sort field. As an example, if your controller defines a default sort of['Users.name' => 'desc']you can now use eitherUsers.nameornameas your sort key.
Error
ExceptionRendererwill now look for prefixed error controllers when handling exceptions. This allows you to define custom error controller logic for each routing prefix in your application.ErrorHandlerMiddlewarewill now include previous exceptions in logging.
Filesystem
Cake\Filesystem\Folder::normalizeFullPath()was added.
Form
Cake\Form\Form::setData()was added. This method makes defining default values for forms simpler.Cake\Form\Form::getData()was added.
Http
Cake\Http\ServerRequest::setTrustedProxies()was added.Cake\Http\Clientwill now default to use a Curl based adapter if thecurlextension is installed.- New constants have been added to the
SecurityHeadersMiddleware. The new constants are used to build the components of HTTP headers.
Mailer
Cake\Mailer\TransportFactoryandCake\Mailer\TransportRegistrywere added. This class extracts transport creation out of Email, allowing Email to become simpler in the future.
ORM
Cake\ORM\EntityTrait::hasErrors()was added. This method can be used to check whether or not an entity has errors more efficiently thangetErrors()does.- Updating has many association data now respects
_ids. This makes patching has many associations work the same as creating new entities, and creates consistency with belongs to many associations.
Shell
cake i18n extracthas a new--relative-pathsoption that makes path comments in POT files relative to the application root directory instead of absolute paths.cake i18n extracthas a new--marker-erroroption that enables reporting of translation functions that use non-static values as comments in POT files.
TestSuite
- New assertion methods were added to
IntegrationTestCase:assertResponseNotEquals()assertHeaderNotContains()assertRedirectNotContains()assertFlashElement()assertFlashElementAt()
- The custom assertions provided by
IntegrationTestCaseandConsoleIntegrationTestCaseare now implemented through constraint classes. TestCase::loadPlugins(),removePlugins()andclearPlugins()were added to make working with dynamically loaded plugins easier now thatPlugin::load()andPlugin::unload()are deprecated.getMockForModel()now supportsnullfor the$methodsparameter. This allows you to create mocks that still execute the original code. This aligns the behavior with how PHPUnit mock objects work.- Added
EmailTraitto help facilitate testing emails. - The default messages for integration assertions have been improved to provide more context from the exception that was raised if possible.
Utility
Cake\Utility\Text::getTransliterator()was added.Cake\Utility\Text::setTransliterator()was added.Cake\Utility\Xml::loadHtml()was added.
Validation
Cake\Validation\Validation::iban()was added for validating international bank account numbers.Cake\Validation\Validator::allowEmptyString(),allowEmptyArray(),allowEmptyDate(),allowEmptyTime(),allowEmptyDateTime(), andallowEmptyFile()were added. These new methods replaceallowEmpty()and give you more control over what a field should consider empty.
View
FormHelpernow supports aconfirmJstemplate variable which allows the javascript snippet generated for confirmation boxes to be customized.FormHelpernow has aautoSetCustomValidityoption for setting HTML5 validity messages from custom validation messages. See: Html5 Validity MessagesViewBuilderhadsetVar(),setVars(),getVar(),getVars()andhasVar()added. These methods will replace the publicviewVarsproperty defined inViewVarsTrait.PaginatorHelperwill now match unprefixed sort keys to model prefixed ones on the default model. This allow smooth operation with the changes made inCake\Datasource\PaginatorFormHelperwill now readmaxLengthvalidator rules and use them to automatically define themaxlengthattribute on HTML inputs if a max length is not provided in the input options.