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::$headers
is deprecated. UsegetHeaders()
orgetHeaderLine()
instead.Cake\Http\Client\Response::$body
is deprecated. UsegetStringBody()
instead.Cake\Http\Client\Response::$json
is deprecated. UsegetJson()
instead.Cake\Http\Client\Response::$xml
is deprecated. UsegetXml()
instead.Cake\Http\Client\Response::$cookies
is deprecated. UsegetCookies()
instead.Cake\Http\Client\Response::$code
is 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\Cookie
instances. Cake\Validation\Validation::cc()
has been renamed tocreditCard()
.Cake\View\ViewVarsTrait::viewOptions()
is deprecated. UseviewBuilder()->setOptions()
instead.Cake\View\View::$request
is protected now. UseView::getRequest()/setRequest()
to access a View's request instance in other contexts.Cake\View\View::$response
is protected now. UseView::getResponse()/setResponse()
to access a View's response instance in other contexts.Cake\View\View::$templatePath
is protected now. UsegetTemplatePath()/setTemplatePath()
instead.Cake\View\View::$template
is protected now. UsegetTemplate()/setTemplate()
instead.Cake\View\View::$layout
is protected now. UsegetLayout()/setLayout()
instead.Cake\View\View::$layoutPath
is protected now. UsegetLayoutPath()/setLayoutPath()
instead.Cake\View\View::$autoLayout
is protected now. UseenableAutoLayout()/isAutoLayoutEnabled()
instead.Cake\View\View::$theme
is protected now. UsegetTheme()/setTheme()
instead.Cake\View\View::$subDir
is protected now. UsegetSubDir()/setSubDir()
instead.Cake\View\View::$plugin
is protected now. UsegetPlugin()/setPlugin()
instead.Cake\View\View::$name
is protected now. UsegetName()/setName()
instead.Cake\View\View::$elementCache
is protected now. UsegetElementCache()/setElementCache()
instead.Cake\View\View::$Blocks
is protected now. Use public methods on View to interact with blocks.Cake\View\View:$helpers
is protected now. Usehelpers()
to interact with the HelperRegistry instead.Cake\View\View::$uuids
is deprecated and will be removed in 4.0Cake\View\View::uuid()
is deprecated and will be removed in 4.0Cake\View\Cell::$template
is protected now. UseviewBuilder()->getTemplate()/setTemplate()
instead.Cake\View\Cell::$plugin
is protected now. UseviewBuilder()->getPlugin()/setPlugin()
instead.Cake\View\Cell::$helpers
is protected now. UseviewBuilder()->getHelpers()/setHelpers()
instead.Cake\View\Cell::$action
is protected now.Cake\View\Cell::$args
is protected now.Cake\View\Cell::$View
is protected now.Cake\View\Cell::$request
is protected now.Cake\View\Cell::$response
is protected now.Cake\View\ViewVarsTrait::$viewVars
is 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\Email
have 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::$theme
is removed. UseView::getTheme()
instead.Helper::$plugin
is removed. UseView::getPlugin()
instead.Helper::$fieldset
andHelper::$tags
are deprecated as they are unused.Helper::$helpers
is now protected and should not be accessed from outside a helper class.Helper::$request
is 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\ExceptionRender
are now protected:$error
,$controller
,$template
and$method
. - Using underscored fixtures names in
TestCase::$fixtures
is 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\ConsoleIntegrationTestCase
is deprecated. You should includeCake\TestSuite\ConsoleIntegrationTestTrait
into your test case class instead.
Behavior Changes
Cake\Database\Type\IntegerType
will 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 offalse
when no result is found.Cake\Database\Statement\BufferedStatement
no longer inherits fromStatementDecorator
and no longer implements theIteratorAggregate
interface. Instead it directly implements theIterator
interface to better support using statements with collections.- When marshalling data from the request into entities, the ORM will now convert non-scalar data into
null
for boolean, integer, float, and decimal types. ExceptionRenderer
will 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_method
key toGET
when generating URLs withRouter::url()
.
New Features
Cache
- The
ArrayEngine
was 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
Paginator
will now match unprefixedsort
values 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.name
orname
as your sort key.
Error
ExceptionRenderer
will 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.ErrorHandlerMiddleware
will 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\Client
will now default to use a Curl based adapter if thecurl
extension 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\TransportFactory
andCake\Mailer\TransportRegistry
were 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 extract
has a new--relative-paths
option that makes path comments in POT files relative to the application root directory instead of absolute paths.cake i18n extract
has a new--marker-error
option 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
IntegrationTestCase
andConsoleIntegrationTestCase
are 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 supportsnull
for the$methods
parameter. This allows you to create mocks that still execute the original code. This aligns the behavior with how PHPUnit mock objects work.- Added
EmailTrait
to 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
FormHelper
now supports aconfirmJs
template variable which allows the javascript snippet generated for confirmation boxes to be customized.FormHelper
now has aautoSetCustomValidity
option for setting HTML5 validity messages from custom validation messages. See: Html5 Validity MessagesViewBuilder
hadsetVar()
,setVars()
,getVar()
,getVars()
andhasVar()
added. These methods will replace the publicviewVars
property defined inViewVarsTrait
.PaginatorHelper
will now match unprefixed sort keys to model prefixed ones on the default model. This allow smooth operation with the changes made inCake\Datasource\Paginator
FormHelper
will now readmaxLength
validator rules and use them to automatically define themaxlength
attribute on HTML inputs if a max length is not provided in the input options.