Stable Release in branch 4.1
4.1.7
Released 12 Dec 2020
(5 years ago)
SoftwareCakePHP
Version4.1
Status
End of life
Supported
PHP versions
PHP 7.2+
Initial release4.1.0
04 Jul 2020
(6 years ago)
Latest release4.1.7
12 Dec 2020
(5 years ago)
End of security fixesUnavailable
Release noteshttps://github.com/cakephp/cakephp/releases/tag/4.1.7
Source codehttps://github.com/cakephp/cakephp/tree/4.1.7
Documentationhttps://book.cakephp.org/4/en/index.html
Downloadhttps://book.cakephp.org/4/en/installation.html
CakePHP 4.1 ReleasesView full list

What Is New in CakePHP 4.1?

CakePHP 4.1 is a feature and maintenance release. It introduces several new helpers, streamlines development with quality-of-life improvements, and addresses bugs from the 4.0 series. The update maintains backward compatibility while adding useful tools for everyday coding tasks.

Category Key Changes
New Features New CookieHelper, AssetMix helper, Request::is() method, and FormProtector.
Improvements Better constraint builder for queries, enhanced TestSuite light/dark themes, and improved Mailer assertions.
Bug Fixes Fixes for validation, ORM behavior, and various other components.
Deprecated Several methods and properties are marked for removal in 4.2, including some in Database\Log\LoggedQuery and View\Helper\FormHelper.

What new helpers were added?

CakePHP 4.1 adds two practical helpers for frontend and security tasks. The CookieHelper simplifies reading cookie values directly within view templates, which is handy for conditional rendering based on cookie data.

The AssetMixHelper integrates seamlessly with Laravel Mix for managing frontend assets. In practice, this means you can easily reference hashed asset files from your Mix manifest without writing custom PHP logic.

How does the new Request::is() method work?

This method provides a cleaner way to check the current request's HTTP method. Instead of using string comparisons on $this->request->getMethod(), you can now use $this->request->is('post').

It supports checking for multiple methods at once, like is(['post', 'put']). This matters because it leads to more readable and expressive controller code, aligning with the framework's goal of developer convenience.

What improvements were made to the Database layer?

The constraint builder for Query::where() and Query::having() received significant enhancements. You can now pass complex expressions and closure-based conditions more intuitively.

// Example of using a closure with the constraint builder
$query->where(function ($exp) {
    return $exp->eq('author_id', 2)->gte('view_count', 100);
});

This change reduces boilerplate and makes building dynamic, nested query conditions much simpler.

Are there new testing features?

Yes, the IntegrationTestTrait now includes a disableErrorHandlerMiddleware() method. This allows you to see the full stack trace during test failures instead of a formatted error page, speeding up debugging.

Additionally, the test suite runner's UI got visual upgrades with light and dark theme support. For mailer tests, new assertions like assertMailSentTo and assertMailContainsAttachment provide more precise verification.

What should I know about deprecations?

Several elements are soft-deprecated in 4.1, meaning they will be removed in 4.2. Key ones include the logged property in Database\Log\LoggedQuery and the input property in View\Helper\FormHelper.

You should run your application with debug enabled to see deprecation warnings. The FormProtector class is also deprecated in favor of the already existing FormTamperProtector middleware.

FAQ

Is CakePHP 4.1 a breaking change from 4.0?
No, it's a backward-compatible release. You can upgrade from 4.0 without changing your application code, but you should review deprecation warnings to prepare for 4.2.

When should I use the new CookieHelper?
Use it in your view templates (CTP files) when you need to check a cookie's value to conditionally modify HTML output. It's a convenience tool that avoids injecting cookie logic from controllers.

What is the main benefit of the AssetMix helper?
It automates the generation of versioned asset URLs when using Laravel Mix. This solves the cache-busting problem for CSS and JavaScript files in production environments.

How does FormProtector differ from the existing CSRF protection?
The deprecated FormProtector class was a lower-level component. The framework now uniformly uses the FormTamperProtector middleware, which provides the same security features in a more integrated way.

Are there any changes to how I write fixture classes?
No, the fixture system remains unchanged in 4.1. The improvements are focused on the test suite runner's interface and new assertion methods, not on the fixture structure itself.

Releases In Branch 4.1

VersionRelease date
4.1.712 Dec 2020
(5 years ago)
4.1.607 Nov 2020
(5 years ago)
4.1.504 Oct 2020
(5 years ago)
4.1.405 Sep 2020
(5 years ago)
4.1.315 Aug 2020
(5 years ago)
4.1.208 Aug 2020
(6 years ago)
4.1.118 Jul 2020
(6 years ago)
4.1.004 Jul 2020
(6 years ago)
4.1.0-RC221 Jun 2020
(6 years ago)
4.1.0-RC131 May 2020
(6 years ago)
4.1.0-beta115 May 2020
(6 years ago)