3.9 Migration Guide
CakePHP 3.9 is an API compatible upgrade from 3.8. This page outlines the changes and improvements made.
To upgrade to 3.9.x run the following composer command:
bash
php composer.phar require --update-with-dependencies "cakephp/cakephp:3.9.*"Deprecations
ConsoleIo::info(),success(),warning()anderror()will no longer acceptnullvalues in themessageparameter in 4.0.- Using a comma separated string for
$fixturesin test cases is deprecated. Instead use an array, or implement the newgetFixtures()method on your test case classes. Validator::errors()was renamed toValidator::validate().FormHelper::create()now emits deprecation warnings when the$contextparameter is a boolean or string. These values trigger fatal errors in 4.0 and will need to be updated before upgrading.- The magic method signature for
FunctionBuilder::cast([...])is deprecated. UseFunctionBuilder::cast('field', 'type')instead. - Abandoned
zendframeworkpackage has been replaced with laminas which provides backwards-compatible classes.
New Features
Cache
MemcachedEngine::write()andadd()no longer cap duration to 30 days. Instead all expiration values are forwarded to memcache.
Console
ConsoleIo::abort()was added.- Command classes can implement the
defaultName()method to overwrite the conventions based CLI name.
Database
Driver::newTableSchema()was added. This hook method lets you customize which the class used for schema metadata.FunctionBuilder::cast()was added.Query::orderAsc()andQuery::orderDesc()now accept Closure's as their field enabling you to use build complex order expressions with the providedQueryExpressionobject.
Datasource
Cake\Datasource\SimplePaginatorwas added. This class makes paginating very large results more efficient. It skips running the potentially expensivecount()query. If you only use 'next' and 'previous' navigation in your pagination controls this class can be a good solution.
Http
Cake\Http\Client\Response::isSuccess()was backported from 4.0Cake\Http\Middleware\CspMiddlewarewas backported from 4.0BaseApplication::addOptionalPlugin()was added. This method handles loading plugins, and handling errors for plugins that may not exist because they are dev dependencies.
I18n
Number::FORMAT_CURRENCY_ACCOUNTINGwas added.Number::CURRENCY_ACCOUNTINGwas added.Number::getDefaultCurrencyFormat()andNumber::setDefaultCurrencyFormat()were added. These methods let you define the formatting style for currency values.- The
setJsonEncodeFormatmethod onTime,FrozenTime,DateandFrozenDatenow accepts a callable that can be used to return a custom string. - The i18n global functions now only return strings. The changes made to 4.0 to remove the null return value when no translation string is provide have been backported to 3.9.
- Lenient parsing can be disabled for
parseDateTime()andparseDate()usingdisableLenientParsing(). The default is enabled - the same as IntlDateFormatter.
ORM
Table::saveManyOrFail()method has been added that will throwPersistenceFailedExceptionwith the specific entity that failed in case of an error. The entities are saved within a transaction.Table::deleteMany()andTable::deleteManyOrFail()methods have been added for removing many entities at once including callbacks. The entities are removed within a transaction.TableLocator::clear()now resets the internaloptionsarray.- BelongsToMany associations now respect the bindingKey set in the junction table's BelongsTo association. Previously, the target table's primary key was always used instead.
Query::clearResult()was added. This method lets you remove the result from a query so you can re-execute it.
TestSuite
TestCase::getFixtures()was added. This method lets you generate your fixture list using application specific logic if necessary.TestSuite\EmailTrait::assertMailContainsAttachment()was added.
Utility
Hash::combine()now acceptsnullfor the$keyPathparameter. Providing null will result in a numerically indexed output array.Hash::sort()now accepts theSORT_ASCandSORT_DESCconstants in the direction parameter.Text::uuid()now usesrandom_int()with PHP 5.6 insted ofmt_rand(). This adds a dependency on paragonie/random_compat which implements it for PHP 5.6.
Validation
- The 'empty' field detection in
Validatornow considersUploadedFileInterfaceobjects that haveUPLOAD_ERR_NO_FILEas their error code to be empty. Validation::notAlphaNumeric()andValidator::notAlphaNumeric()were backported from 4.x.Validation::asciiAlphaNumeric()andValidator::asciiAlphaNumeric()were backported from 4.x.Validation::notAsciiAlphaNumeric()andValidator::notAsciiAlphaNumeric()were backported from 4.x.
View
FormHelperhad theselectedClasstemplate variable added. This template key controls the class name used when a radio or checkbox is selected.TextHelper::slug()was backported from 4.0.