CakePHP 2.0 released: What’s new?

C

“CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. Using commonly known design patterns like MVC and ORM within the convention over configuration paradigm, CakePHP reduces development costs and helps developers write less code. ”

And now, it even got better. After a year and a half of coding, CakePHP 2.0 is released.

I will first talk about some cool new features and explain some of them later.

New features

  • Dropped PHP 4 support and we have refactored all the code to be strictly compliant with PHP 5.2+.
  • Use of native features like exceptions, PDO, SPL, json_encode and much more.
  • Embraced the PSR-0 recommendation for file naming. Now all your classes map to a file with the same name. Less things to remember!
  • New Error and Exception handlers provide easier to configure, and ease working with errors such as page not found, unauthorized error and lots more.
  • Improved I18n functions for easier multilingual development.
  • Support for injecting your own objects to act as CakePHP libraries, such as component, helpers and behaviors, no more excuses for modifying core files.
  • Console libraries rebuilt from scratch, automatic help generation, parameter checking, and colors!
  • New Request and Response objects for easier handling of HTTP requests.
  • Better session handling for easier custom engines. Put your sessions into storage systems like Memcache with less effort.
  • Completely refactored Auth system. It is now easier to configure and plug in your own implementations for external login services or your permissions system.
  • Brand new email library with support for multiple transports. With easy to use global configuration, logging, and charset support.
  • Dropped SimpleUnit in favor of PHPUnit. PHPUnit is the defacto testing framework for PHP with support for more options, better mock objects, and improved console output [16]
  • Reworked the SecurityComponent to suck less, now you can more easily protect your apps against CSRF and form tampering attacks while having fun.
  • Improved support for PostgreSql, SQLite and SqlServer, they are now first class citizens along with Mysql datasource.
  • HTML 5 form inputs support in form helper.
  • A Sexier default look taking advantage of new CSS 3 features.
  • A lot faster, almost everything is now lazy-loaded, and even on debug mode you will feel your applications flying.

CakePHP 2.0 completely dropped the PHP 4 support and is now supporting PHP 5.2.6 and above. This was expected.

Models

The model construction process has been made lighter. Model associations are now lazy loaded, applications with lots of models and associations will see great time reductions in the bootstrap process.

Now models won’t require a database connection in the construction process. The database will be accessed for the first time only when a find operation is issued or information for one of the columns is required.

Views

View will now always have the last rendered content (view or layout) accessible through $this->output. In helpers you can use $this->_View->output. Modifying this property will change the content that comes out of the view rendering.

Helpers

There are some interesting new features inside powerful CakePHP Helpers:

  • FormHelper now supports all HTML5 input types and custom input types. Just use the input type you want as the method on the helper. For example range() would create an input with type = range.
  • postLink() and postButton() Creates link/button to access some page using HTTP method POST. With this, in your controller you can avoid some action, like delete, to be accessed by GET method.
  • select() with multiple = checkbox, now treats the 'id' attribute as a prefix for all the generated options.
  • getCrumbsList() Creates breadcrumb links wrapped in <li> elements in HTMLHelper

Error handling

The error handling implementation has dramatically changed in 2.0. Exceptions have been introduced throughout the framework, and error handling has been updated to offer more control and flexibility.

PHPUnit

All of the core test cases and supporting infrastructure have been ported to use PHPUnit 3.5. Of course you can continue to use SimpleTest in your application by replacing the related files.

No further support will be given for SimpleTest and it is recommended that you migrate to PHPUnit as well.

Database Objects

Cake 2.0 introduces some changes to Database objects that should not greatly affect backwards compatibility. The biggest one is the adoption of PDO for handling database connections.

If you are using a vanilla installation of PHP 5 you will already have installed the needed extensions, but you may need to activate individual extensions for each driver you wish to use.

Console

CakePHP features not only a web framework but also a console framework for creating console applications. Console applications are ideal for handling a variety of background tasks such as maintenance, and completing work outside of the request-response cycle. CakePHP console applications allow you to reuse your application classes from the command line.

CakePHP comes with a number of console applications out of the box. Some of these applications are used in concert with other CakePHP features (like ACL or i18n), and others are for general use in getting you working faster.

One of the cool things is that the console app is now colorized to easier spot error messages and other critical information.

Conclusion

CakePHP 2.0 is a great step for this framework. I mentioned only the biggest features but there are even more.

I am looking forward to write some tutorials, benchmarks and reviews on CakePHP 2.0 to see how it really works in a real world examples. So, stay tuned.

What do you think of CakePHP framework? What frameworks do you use?

About the author

Zvonko Biškup

A passionate web developer with more than 13 years experience in PHP and other web related technology. My main interest is WordPress and new PHP frameworks.
Owner of Influendo Programming.
Enjoys exploring new stuff and possibilities, using new technologies and just having fun developing awesome stuff.

  • Noel

    I am glad to see that great CakePHP has reached the new version. Plenty of new features is mentioned. I can not wait to have a new project and build it in CakePHP.

    I just hope that it will be faster then before.

    Nice post, BTW.

  • Tim

    I have started using CakePHP 2.1 (most recently) as my primary application development framework. If I could recommend any tutorials, I think a PHPUnit configuration (working) would be very helpful 🙂

By Zvonko Biškup

Tags