3.7 Migration Guide
CakePHP 3.7 is an API compatible upgrade from 3.6. This page outlines thechanges and improvements made in 3.7.
To upgrade to 3.7.x run the following composer command:
- php composer.phar require --update-with-dependencies "cakephp/cakephp:3.7.*"
Deprecations
The following is a list of deprecated methods, properties and behaviors. Thesefeatures 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()
isdeprecated. 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 inother contexts.Cake\View\View::$response
is protected now. UseView::getResponse()/setResponse()
to access a View’s response instance inother 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 tointeract with blocks.Cake\View\View:$helpers
is protected now. Usehelpers()
to interactwith 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 propertywill 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 outsidea helper class.Helper::$request
is removed.UseView::getRequest()
,View::setRequest()
instead.Cake\Core\Plugin::load()
andloadAll()
are deprecated. Instead youshould 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 notbe removed until 5.0.0:
Cake\TestSuite\ConsoleIntegrationTestCase
is deprecated. You shouldincludeCake\TestSuite\ConsoleIntegrationTestTrait
into your test caseclass instead.
Behavior Changes
Cake\Database\Type\IntegerType
will now raise an exception when valuesare not numeric when preparing SQL statements and converting database resultsto PHP types.Cake\Database\Statement\StatementDecorator::fetchAll()
now returns anempty 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 bettersupport using statements with collections.- When marshalling data from the request into entities, the ORM will now convertnon-scalar data into
null
for boolean, integer, float, and decimal types. ExceptionRenderer
will now always call handler methods for customapplication exception classes. Previously, custom exception class handlermethods would only be invoked in debug mode.Router::url()
will now default the_method
key toGET
whengenerating URLs withRouter::url()
.
New Features
Cache
- The
ArrayEngine
was added. This engine provides an ephemeral in memorycache implementation. It is ideal for test suites or long running processeswhere 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 tothe primary model if there also exists a matching model prefixed default sortfield. 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 whenhandling exceptions. This allows you to define custom error controller logicfor 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 defaultvalues 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 newconstants are used to build the components of HTTP headers.
Mailer
Cake\Mailer\TransportFactory
andCake\Mailer\TransportRegistry
wereadded. This class extracts transport creation out of Email, allowing Email tobecome simpler in the future.
ORM
Cake\ORM\EntityTrait::hasErrors()
was added. This method can be used tocheck whether or not an entity has errors more efficiently thangetErrors()
does.- Updating has many association data now respects
_ids
. This makes patchinghas many associations work the same as creating new entities, and createsconsistency with belongs to many associations.
Shell
cake i18n extract
has a new—relative-paths
option that makes pathcomments in POT files relative to the application root directory instead ofabsolute paths.cake i18n extract
has a new—marker-error
option that enablesreporting of translation functions that use non-static values as comments inPOT 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()
wereadded 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. Thisaligns 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 providemore 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 internationalbank 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 thejavascript snippet generated for confirmation boxes to be customized.FormHelper
now has aautoSetCustomValidity
option for setting HTML5validity messages from custom validation messages. See: Displaying validation messages in 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 oneson the default model. This allow smooth operation with the changes made inCake\Datasource\Paginator
FormHelper
will now readmaxLength
validator rules and use them toautomatically define themaxlength
attribute on HTML inputs if a maxlength is not provided in the input options.
当前内容版权归 cakephp.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 cakephp.org .