CakePHP 3.1 is a fully API compatible upgrade from 3.0. This page outlines the changes and improvements made in 3.1.
cakephp/apprepo. Your current code base is not affected by this, but it is recommended to use this route class from now on.
Shell::dispatchShell()no longer outputs the welcome message from the dispatched shell.
breakpoint()helper function has been added. This function provides a snippet of code that can be put into
eval()to trigger an interactive console. This is very helpful when debugging in test cases, or other CLI scripts.
--quietconsole options now control stdout/stderr logging output levels.
The following Controller properties are now deprecated:
Instead of setting these properties on your controllers, you should set them on the view using methods with matching names:
// In a controller, instead of $this->layout = 'advanced'; // You should use $this->viewBuilder()->layout('advanced');
These methods should be called after you’ve determined which view class will be used by a controller/action.
storagehas been added. It contains the storage class name that
AuthComponentuses to store user record. By default
SessionStorageis used. If using a stateless authenticator you should configure
checkAuthInhas been added. It contains the name of the event for which auth checks should be done. By default
Controller.startupis used, but you can set it to
Controller.initializeif you want authentication to be checked before you controller’s
beforeFilter()method is run.
containfor authenticator classes have been deprecated. Instead, use the new
finderoption to configure a custom finder method and modify the query used to find a user there.
Auth.redirectsession variable, which is used to get the URL to be redirected to after login, has been changed. It is now set only when trying to access a protected URL without authentication. So
Auth::redirectUrl()returns the protected URL after login. Under normal circumstances, when a user directly accesses the login page,
Auth::redirectUrl()returns the value set for
FlashComponentnow stacks Flash messages when set with the
__call()method. This means that the structure in the Session for stored Flash messages has changed.
Cake\Network\Exception\InvalidCsrfTokenExceptioninstead of the
RequestHandlerComponentnow switches the layout and template based on the parsed extension or
Acceptheader in the
beforeRender()callback instead of
viewClassMap()are deprecated. You should use
config()to modify this configuration data at runtime.
viewClassMapare defined in the component settings, they will overwrite the default values. This change makes it possible to remove the default configuration.
multipart/form-datawould always be used. In 3.1,
multipart/form-datais only used when file uploads are present. When there are no file uploads,
application/x-www-form-urlencodedis used instead.
You can now Lazily Eager Load Associations. This feature allows you to conditionally load additional associations into a result set, entity or collection of entities.
newEntity() method now support the
option. This option allows you to restrict hasMany/belongsToMany association
marshalling to only use the
_ids list. This option defaults to
Associationobjects as parameters. These parameter types will select all the columns on the provided table or association instance’s target table.
Query::distinct()now accepts a string to distinct on a single column.
DAYOFWEEKraw SQL functions have been abstracted to
XmlViewto serialize all view variables instead of explicitly specifying them.
View::$viewPathis deprecated. You should use
View::$viewis deprecated. You should use
View::TYPE_VIEWis deprecated. You should use
SessionHelperhas been deprecated. You can use
FlashHelpercan render multiple messages if multiple messages where set with the
FlashComponent. Each message will be rendered in its own element. Messages will be rendered in the order they were set.
templateVarshas been added.
templateVarsallows you to pass additional variables to your custom form control templates.
Transportclasses have been moved under the
Cake\Mailernamespace. Their former namespaces are still usable as class aliases have been set for them.
defaultemail profile is now automatically set when an
Mailerclass was added. This class helps create reusable emails in an application.
Time::fromNow()has been added. This method makes it easier to calculate differences from ‘now’.
Time::i18nFormat()now supports non-gregorian calendars when formatting dates.