What's New in CakePHP 3.0.0?

    Hello dear readers. In this article, I would like to write about the new version of CakePHP and revive the interest in this wonderful PHP framework. The last CakePHP blog post is dated almost a year ago and many would have thought that the framework had ceased to exist, but this is not so. It is very actively developing and very popular in Western countries and it 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 the possibilities this framework provides now, and then dwell on the new products that will appear in 3.0.0.

    Why is it worth using CakePHP?


    CakePHP makes creating web applications simpler, faster, and writing less code. There are no complex XML or YAML files. Just configure the database connection and start development. Instead of thinking about where, what, and how to better place it, rely on thoughtful CakePHP conventions to help you design your application. Things that are needed in almost every project are already implemented. Support for multilingualism, access to databases, caching, validation, authentication and much more are already built into the core of the framework. Here is a short list of CakePHP 2.5.5 features:

    • Compatible with PHP versions 5.2.8 and higher
    • Built-in ORM for interacting with the database
    • Scaffolding - building an application framework for the database structure
    • Command line code generation
    • MVC architecture
    • Query Manager, Flexible URLs, and Routing
    • Built-in validation
    • Fast and flexible templating with PHP syntax and helpers
    • View Helpers for AJAX, JavaScript, HTML forms, etc.
    • Email, cookie, security, session, and request components
    • Flexible ACL
    • Data normalization
    • Flexible caching
    • Localization support
    • Works from any directory of the site and practically does not require Apache configuration
    • Excellent documentation and active CakePHP community
    • The framework is released 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 actively ongoing and CakePHP 3.0.0-beta has just been released, 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

    • The same directory structure for applications and plugins. This will make it possible when working with plugins to feel as if you are working in a small modular application.
    • src / Config is 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 be in src / Template / Bake 
    • Plugins that use vendor prefixes (e.g. 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 name of the folder in the plugin folder, so the plugin will be installed in plugins / AcmeCorp / User
    • 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 is absent in the request and is in the entities
    • Now it's easier to implement custom column types using the _initializeSchema method for tables
    • Query :: newExpr () now allows SQL statements
    • Nullable conditions are now easier to create. 'field IS' => $valwill generate the correct SQL when $ val is not NULL.
    • Conditions with the IN keyword are now working better with empty data
    • Added Query :: autoFields (). This controls whether the fields for the main table were automatically selected.
    • The ability to pass crawler options to individual paginator crawlers using the FinderOptions key
    • It is now 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 finer control for mass applications.
    • 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 in CakePHP wrapper to avoid repeating configuration lines and add some CakePHP features

    Important changes

    • Separation of the framework into separate components for independent use: collections, validation, utilities, events, kernel
    • The router class has been rewritten and new methods have been added to make the routing files more consistent with the DRY principle than before. The default routes provided by CakePHP have been deleted. Their place was taken by a small set of routes provided to help at the prototype stage of application development.
    • Merging themes and plugins. Now you can use any plugin as a theme. This makes packaging and distribution as easy as plugins and allows the use of helpers and cells.
    • There View Take the Cells - are small classes, which are functionally similar to the controllers, but can be used directly in view, to retrieve data from any source and display a certain pattern
    • Creating View objects has been simplified; they are now no longer dependent on controllers
    • Redesigned manager filters - filters are now registered as object instances, and not through configuration data, which added a nested dependency
    • New session object. In CakePHP 3.0, you can access a session using a request object$this->request->session()
    • Previously, CookieComponent could only work in one namespace. Redesigned CookieComponent Separates Cookie Namespace Configuration from Cookie Processing
    • 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 several kinds of messages in a simple way. A separate component and helper FlashHelper and FlashComponent were created for this.
    • CacheHelper has been removed from CakePHP. The development team recommends that the functions of this assistant be performed on a separate server, for example Varnish.
    • The class L10n has been removed. Built on ext / intl and Aura / Intl, the new localization subsystem offers a more powerful replacement syntax and preserves backward compatibility of the formatter based on sprintf ()
    • Added Validator :: notEmpty () method
    • Request :: isMobile now uses an external library to match the 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 the HTTP request in your application.
    • DebugKit appeared - this is a toolbar for an application that collects useful statistics about your code, such as time and memory, executed requests, log messages and view variables
    • Console improvements
    • Improved performance by speeding up the loading process and generating some parts of the template helpers
    • New Bakery Template

    Plugins


    More and more plugins for version 3.0 begin to appear every day. Here are just the most interesting of them:
    • TwigView - Twig template engine
    • Imagine - image plugin
    • Geo - contains libraries of utilities and behaviors for working with geo data
    • Blame - registers a user ID that modifies a row in the database
    • CakePdf - Generates PDF Files Using Various Engines
    • Authenticate - authorization and authentication adapters
    • TinyAuth - lightweight authorization system
    • TwitterBootstrap - a plugin for generating bootstrap interfaces
    • Whoops - alternative exception renderer with convenient debugging interface
    • Assetic - minifies and processes (pre-process) CSS and Javascript

    You can download the 3.0.0-beta release or just use composer create-project -s dev cakephp/appit to try CakePHP 3.0 now.

    useful links


    CakePHP - Official
    Cookbook Framework Page - Official
    API Documentation - Class Description CakePHP
    GitHub - Source Code for All
    Plugins Releases -
    Bakery Framework Tutorial Repository - Tips, Tricks, and Articles
    Community Center - List of Official Community Pages and Channels

    This article very briefly describes the full list changes. If readers will be interested in this topic, then in the following articles you can read in detail about the most significant changes and ways of migration from version 2.x.

    Only registered users can participate in the survey. Please come in.

    Are you interested in a CakePHP related topic?

    • 51% Yes, go on! 125
    • 26.1% No, CakePHP has no future. 64
    • 22.8% I don’t care ... 56

    Also popular now: