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 generatenow supports the--excludeparameter.- The constant
CAKEPHP_SHELLis now deprecated and will be removed in CakePHP 3.0.
BakeShell
cake bake modelnow 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 bakefor views, models, controllers, tests and fixtures now supports a-for--forceparameter 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 fixturenow supports a--schemaparameter to allow baking all fixtures with noninteractive "all" while using schema import.
Core
Constants
- Constants
IMAGES_URL,JS_URL,CSS_URLhave been deprecated and replaced with config variablesApp.imageBaseUrl,App.jsBaseUrl,App.cssBaseUrlrespectively. - Constants
IMAGES,JS,CSShave been deprecated.
Object
Object::log()had the$scopeparameter added.
Components
AuthComponent
- AuthComponent now supports proper stateless mode when using 'Basic' or 'Digest' authenticators. Starting of session can be prevented by setting
AuthComponent::$sessionKeyto false. Also now when using only 'Basic' or 'Digest' you are no longer redirected to login page. For more info check theAuthComponentpage. - Property
AuthComponent::$authErrorcan be set to booleanfalseto 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
INNERjoins instead ofLEFTjoins. This improves performance for some database vendors.
Model
Models
Model::save(),Model::saveField(),Model::saveAll(),Model::saveAssociated(),Model::saveMany()now take a newcounterCacheoption. 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
SETcommands when the connection is created. - The MySQL driver now supports SSL options.
View
JsonView
- JSONP support has been added to
JsonView. - The
_serializekey now supports renaming serialized variables. - When debug > 0 JSON will be pretty printed.
XmlView
- The
_serializekey 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, therelattribute defaults to 'stylesheet'. - New option
escapeTitleadded 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:1or?page=1in the URL. This helps prevent duplicate content issues where you would need to use canonical or noindex otherwise.
FormHelper
- The
roundoption was added toFormHelper::dateTime(). Can be set toupordownto 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
emailby default. If you are not seeing email contents in your logs, be sure to add theemailscope 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 thedatakey.- Configuration data is now correctly merged with transport classes.
HttpSocket
HttpSocket::patch()has been added.
I18n
L10n
ellis now the default locale for Greek as specified by ISO 639-3 andgreits alias. The locale folders have to be adjusted accordingly (from /Locale/gre/ to /Locale/ell/).fasis now the default locale for Farsi as specified by ISO 639-3 andperits alias. The locale folders have to be adjusted accordingly (from /Locale/per/ to /Locale/fas/).smeis now the default locale for Sami as specified by ISO 639-3 andsmiits alias. The locale folders have to be adjusted accordingly (from /Locale/smi/ to /Locale/sme/).mkdreplacesmkas default locale for Macedonian as specified by ISO 639-3. The corresponding locale folders have to be adjusted, as well.- Catalog code
inhas been dropped in favor ofid(Indonesian),ehas been dropped in favor ofel(Greek),nhas been dropped in favor ofnl(Dutch),phas been dropped in favor ofpl(Polish),szhas been dropped in favor ofse(Sami). - Kazakh has been added with
kazas locale andkkas catalog code. - Kalaallisut has been added with
kalas locale andklas catalog code. - The constant
DEFAULT_LANGUAGEhas been deprecated in favor of Configure valueConfig.language.
Logging
- Log engines do not need the suffix
Loganymore 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 likeDatabaseLoggerthat does not follow the convention to use a suffixLogfor your class name you have to adjust your class name toDatabaseLog. You should also avoid class names likeSomeLogLogwhich include the suffix twice at the end.
FileLog
- Two new config options
sizeandrotatehave 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
Sanitizeclass has been deprecated.
Validation
Validation::date()now supports theyandymformats.- The country code of
Validation::phone()for Canada has been changed fromcantocato unify the country codes for validation methods according to ISO 3166 (two letter codes).
CakeNumber
- The currencies
AUD,CADandJPYhave been added. - The symbols for
GBPandEURare now UTF-8. If you upgrade a non-UTF-8 application, make sure that you update the static$_currenciesattribute with the appropriate HTML entity symbols (£and€) before you use those currencies. - The
fractionExponentoption 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
prettyhas been added toXml::fromArray()to return nicely formatted Xml
Error
ErrorHandler
- New configuration option
skipLoghas 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.fullBaseUrlConfigure value. They replaceFULL_BASE_URLwhich is now deprecated.Router::parse()now parses query string arguments.