2.4 Migration Guide
CakePHP 2.4 is a fully API compatible upgrade from 2.3. This page outlines the changes and improvements made in 2.4.
Console
- Logged notice messages will now be colourized in terminals that support colours.
- ConsoleShell is now deprecated.
SchemaShell
cake schema generate
now supports the--exclude
parameter.- The constant
CAKEPHP_SHELL
is now deprecated and will be removed in CakePHP 3.0.
BakeShell
cake bake model
now supports baking$behaviors
. Finding lft, rght and parent_id fields in your table it will add the Tree behavior, for example. You can also extend the ModelTask to support your own behaviors to be recognized.cake bake
for views, models, controllers, tests and fixtures now supports a-f
or--force
parameter to force overwriting of files.- Tasks in core can now be aliased in the same way you would Helpers, Components and Behaviors
FixtureTask
cake bake fixture
now supports a--schema
parameter to allow baking all fixtures with noninteractive "all" while using schema import.
Core
Constants
- Constants
IMAGES_URL
,JS_URL
,CSS_URL
have been deprecated and replaced with config variablesApp.imageBaseUrl
,App.jsBaseUrl
,App.cssBaseUrl
respectively. - Constants
IMAGES
,JS
,CSS
have been deprecated.
Object
Object::log()
had the$scope
parameter added.
Components
AuthComponent
- AuthComponent now supports proper stateless mode when using 'Basic' or 'Digest' authenticators. Starting of session can be prevented by setting
AuthComponent::$sessionKey
to false. Also now when using only 'Basic' or 'Digest' you are no longer redirected to login page. For more info check theAuthComponent
page. - Property
AuthComponent::$authError
can be set to booleanfalse
to suppress flash message from being displayed.
PasswordHasher
- Authenticating objects now use new password hasher objects for password hash generation and checking. See Hashing Passwords for more info.
DbAcl
- DbAcl now uses
INNER
joins instead ofLEFT
joins. This improves performance for some database vendors.
Model
Models
Model::save()
,Model::saveField()
,Model::saveAll()
,Model::saveAssociated()
,Model::saveMany()
now take a newcounterCache
option. You can set it to false to avoid updating counter cache values for the particular save operation.Model::clear()
was added.
Datasource
- The Mysql, Postgres, and Sqlserver datasources now support a 'settings' array in the connection definition. This key => value pair will be issued as
SET
commands when the connection is created. - The MySQL driver now supports SSL options.
View
JsonView
- JSONP support has been added to
JsonView
. - The
_serialize
key now supports renaming serialized variables. - When debug > 0 JSON will be pretty printed.
XmlView
- The
_serialize
key now supports renaming serialized variables. - When debug > 0 XML will be pretty printed.
HtmlHelper
- The API for
HtmlHelper::css()
has been been simplified. You can now provide an array of options as the second argument. When you do, therel
attribute defaults to 'stylesheet'. - New option
escapeTitle
added toHtmlHelper::link()
to control escaping of only link title and not attributes.
TextHelper
TextHelper::autoParagraph()
has been added. It allows to automatically convert text into HTML paragraphs.
PaginatorHelper
PaginatorHelper::param()
has been added.- The first page no longer contains
/page:1
or?page=1
in the URL. This helps prevent duplicate content issues where you would need to use canonical or noindex otherwise.
FormHelper
- The
round
option was added toFormHelper::dateTime()
. Can be set toup
ordown
to force rounding in either direction. Defaults to null which rounds half up according tointerval
.
Network
CakeRequest
CakeRequest::param()
has been added.CakeRequest::is()
has been modified to support an array of types and will return true if the request matches any type.CakeRequest::isAll()
has been added to check that a request matches all the given types.
CakeResponse
CakeResponse::location()
has been added to get or set the redirect location header.
CakeEmail
- Logged email messages now have the scope of
email
by default. If you are not seeing email contents in your logs, be sure to add theemail
scope to your logging configuration. CakeEmail::emailPattern()
was added. This method can be used to relax email validation rules. This is useful when dealing with certain Japanese hosts that allow non-compliant addresses to be used.CakeEmail::attachments()
now allows you to provide the file contents directly using thedata
key.- Configuration data is now correctly merged with transport classes.
HttpSocket
HttpSocket::patch()
has been added.
I18n
L10n
ell
is now the default locale for Greek as specified by ISO 639-3 andgre
its alias. The locale folders have to be adjusted accordingly (from /Locale/gre/ to /Locale/ell/).fas
is now the default locale for Farsi as specified by ISO 639-3 andper
its alias. The locale folders have to be adjusted accordingly (from /Locale/per/ to /Locale/fas/).sme
is now the default locale for Sami as specified by ISO 639-3 andsmi
its alias. The locale folders have to be adjusted accordingly (from /Locale/smi/ to /Locale/sme/).mkd
replacesmk
as default locale for Macedonian as specified by ISO 639-3. The corresponding locale folders have to be adjusted, as well.- Catalog code
in
has been dropped in favor ofid
(Indonesian),e
has been dropped in favor ofel
(Greek),n
has been dropped in favor ofnl
(Dutch),p
has been dropped in favor ofpl
(Polish),sz
has been dropped in favor ofse
(Sami). - Kazakh has been added with
kaz
as locale andkk
as catalog code. - Kalaallisut has been added with
kal
as locale andkl
as catalog code. - The constant
DEFAULT_LANGUAGE
has been deprecated in favor of Configure valueConfig.language
.
Logging
- Log engines do not need the suffix
Log
anymore in their setup configuration. So for the FileLog engine it suffices to define'engine' => 'File'
now. This unifies the way engines are named in configuration (see Cache engines for example). Note: If you have a Log engine likeDatabaseLogger
that does not follow the convention to use a suffixLog
for your class name you have to adjust your class name toDatabaseLog
. You should also avoid class names likeSomeLogLog
which include the suffix twice at the end.
FileLog
- Two new config options
size
androtate
have been added for FileLog engine. - In debug mode missing directories will now be automatically created to avoid unnecessary errors thrown.
SyslogLog
- The new logging engine SyslogLog was added to stream messages to syslog.
Cache
FileEngine
- In debug mode missing directories will now be automatically created to avoid unnecessary errors thrown.
Utility
General
pr()
no longer outputs HTML when running in CLI mode.
Sanitize
Sanitize
class has been deprecated.
Validation
Validation::date()
now supports they
andym
formats.- The country code of
Validation::phone()
for Canada has been changed fromcan
toca
to unify the country codes for validation methods according to ISO 3166 (two letter codes).
CakeNumber
- The currencies
AUD
,CAD
andJPY
have been added. - The symbols for
GBP
andEUR
are now UTF-8. If you upgrade a non-UTF-8 application, make sure that you update the static$_currencies
attribute with the appropriate HTML entity symbols (£
and€
) before you use those currencies. - The
fractionExponent
option was added toCakeNumber::currency()
.
CakeTime
CakeTime::isPast()
andCakeTime::isFuture()
were added.CakeTime::timeAgoInWords()
has two new options to customize the output strings:relativeString
(defaults to%s ago
) andabsoluteString
(defaults toon %s
).CakeTime::timeAgoInWords()
uses fuzzy terms when time is below thresholds.
Xml
- New option
pretty
has been added toXml::fromArray()
to return nicely formatted Xml
Error
ErrorHandler
- New configuration option
skipLog
has been added, to allow skipping certain Exception types to be logged.Configure::write('Exception.skipLog', array('NotFoundException', 'ForbiddenException'));
will avoid these exceptions and the ones extending them to be be logged when'Exception.log'
config istrue
Routing
Router
Router::fullBaseUrl()
was added together withApp.fullBaseUrl
Configure value. They replaceFULL_BASE_URL
which is now deprecated.Router::parse()
now parses query string arguments.