Hello, dear readers. In this article I would like to write about the new version of
CakePHP and revive interest in this wonderful PHP framework. The last blog post about CakePHP was dated almost a year ago and many might have thought that the framework had ceased to exist, but this is not the case. It is very actively developing and is very popular in Western countries and is used by companies such as
BMW and Hyundai .
The current stable version of CakePHP is 2.5.5. Let's take a quick look at what opportunities this framework provides now, and then we’ll look in detail at the updates that will appear in 3.0.0.
Why use CakePHP?
CakePHP allows you to create web applications easier, faster and write less code. There are no complex XML or YAML files. Simply configure the database connection and start development. Instead of thinking about where, what and how best to place, rely on well-thought CakePHP conventions to help you develop the application. Things that are needed in almost every project have already been implemented. Multilanguage support, database access, caching, validation, authentication, and much more is already built into the framework framework. Here is a brief list of CakePHP 2.5.5 features:
- Compatible with versions of PHP 5.2.8 and higher
- Built-in ORM to interact with the database
- Scaffolding - building an application framework by database structure
- Generating code from the command line
- MVC architecture
- Query Manager, Flexible URLs and Routing
- Built-in validation
- Fast and flexible templating with PHP syntax and helpers
- View Assistants for AJAX, JavaScript, HTML Forms, etc.
- Email, cookie, security, session, and request components
- Flexible ACL
- Data normalization
- Flexible caching
- Localization support
- It works from any site directory and practically does not require Apache configuration.
- Excellent documentation and active CakePHP community
- The framework is licensed under the MIT license, which is ideal for use in commercial projects.
In January 2014, the first preview of CakePHP 3.0.0 was released. Currently, development is underway and CakePHP 3.0.0-beta just recently came out, which means that the release is just around the corner. In the meantime, let's see what's new in the third version.
')
What's new in CakePHP 3.0.0-beta?
Changes in directory structure and naming
- Same directory structure for applications and plugins. This will make it possible while working with plugins to feel as if you are working in a small modular application.
- src / config now / config
- src / bootstrap.php is now /config/bootstrap.php
- Log files are now at the top level of the default directory
- Bake templates should now lie in src / Template / Bake
- Plugins that use vendor prefixes (for example AcmeCorp / Users) are no longer renamed. Instead of using Users.User, you should now use AcmeCorp / Users.User. Also, vendor prefixes will be used as the folder name in the plug-in folder, so the plug-in will be installed in plugins / AcmeCorp / User
- The exception files have been moved to their corresponding namespaces.
ORM improvements
- Added support for Microsoft SQL Server
- Empty associations in BelongsTo and HasOne no longer create an empty entity. Instead, the association property will be null.
- Parameters for all different ORM operations are now consistent.
- You can specify a white list of fields when the data to be sorted are missing in the query and in the entities.
- Now it's easier to implement your own column types using the _initializeSchema method for tables
- Query :: newExpr () now allows SQL expressions
- Conditions with nullable values ​​are now easier to create.
'field IS' => $val
generate the correct SQL when $ val is not NULL. - Conditions with the keyword IN become better to work with empty data
- Added Query :: autoFields (). This controls whether fields for the main table were automatically selected.
- Ability to pass crawler options to individual crawler paginators using the FinderOptions key
- Now it is possible to get a separate column of values ​​from the database using Schema \ Table :: defaultValue ()
- Added accessibleFields as an optional key for newEntity () and patchEntity (). This will allow a more subtle control for the masses.
- TranslateBehavior automatically finds translations based on the current application locale.
- Added Table :: findOrCreate () method
- Ability to override join type for associations using contain ()
- Migrations are now the official CakePHP plugin. It wraps the excellent Phinx library into a CakePHP shell to avoid repeating configuration strings and add some CakePHP features.
Important changes
- Separation of the framework into separate components for independent use: collections, validation, utilities, events, core
- The router class has been rewritten and new methods have been added that allow routing files to more closely comply with the DRY principle than before. The default routes provided by CakePHP have been removed. Their place was taken by a small set of routes provided to help at the prototype stage of application development.
- Merge themes and plugins. Now you can use any plugin as a theme. This makes the packaging and distribution of topics as easy as plug-ins and allows you to use helpers and cells
- View Cells appeared - these are small classes that are similar in functionality to the controllers, but can be used directly in the view to get data from any source and display a specific template.
- Creating View objects has been simplified, they are no longer controller dependent
- The dispatcher's filters have been reworked - the filters are now registered as instances of the object, and not through the configuration data, which added a nested dependency.
- New session object. In CakePHP 3.0, you can access a session using the request object
$this->request->session()
- Previously, CookieComponent could only work in a single namespace. Redesigned CookieComponent separates cookie namespace configuration from handling cookie data
- New Time class - now the Time class can do the same thing as the Carbon and DateTime libraries
- CakePHP 3.0 gives developers more tools to create and render multiple types of messages in a simple way. To do this, a separate component and a helper FlashHelper and FlashComponent were created.
- CacheHelper has been removed from CakePHP. The development team recommends that the functions of this helper be performed on a separate server, for example Varnish.
- Class L10n has been removed. Built on ext / intl and Aura / Intl, the new localization subsystem offers a more powerful replacement syntax and preserves the backward compatibility of the formatter based on sprintf ()
- Added method Validator :: notEmpty ()
- Request :: isMobile now uses external library to match increasing number of mobile devices
- Bcrypt in default passwords
- New logging interface. Now all logging engines implement Psr \ Log \ LoggerInterfaceinterface
- A new IntegrationTestCase class has appeared to test all aspects of an HTTP request in your application.
- DebugKit has appeared - an application toolbar that collects useful statistics about your code, such as time and memory, requests made, log messages and view variables.
- Console enhancements
- Improved performance by speeding up the loading process and generating some parts of the pattern helpers.
- New Bakery Template
Plugins
Every day more and more plugins for version 3.0 are starting to appear. Here are just the most interesting ones:
- TwigView - Twig template engine
- Imagine - plugin for working with images
- Geo - contains libraries of utilities and behavior for working with geo data
- Blame - registers the user ID that modifies the string in the database
- CakePdf - generates PDF files using various engines
- Authenticate - authorization and authentication adapters
- TinyAuth - lightweight authorization system
- TwitterBootstrap - plugin to generate bootstrap interfaces
- Whoops - alternative exceptions renderer with user friendly interface for debugging
- Assetic - minifies and processes (pre-process) CSS and Javascript
You can
download the release 3.0.0-beta or just use the
composer create-project -s dev cakephp/app
to try CakePHP 3.0 now.
useful links
CakePHP - The official framework framework
CookBook - Official Documentation
API - CakePHP Classes Description
GitHub - Source code for all releases.
Plugins - The framework plugin repository
Bakery - Tips, Guides and Articles
Community Center - List of official pages and community channels
This article describes very briefly the complete list of changes. If this topic is interesting to readers, in the following articles you will be able to read in detail about the most significant changes and migration methods from version 2.x.