A little more than two months have passed since the release of the previous version, and the development team presents one of the largest and most serious releases of the fastest PHP framework written as a C-extension. The new version contains many new features, bug fixes and optimizations. We also updated the site and are preparing for major documentation updates and API descriptions. ')
Innovations Phalcon 1.2.0:
The “compiledPath” option in the Volt template engine now accepts an anonymous function that allows you to perform the necessary actions before writing the template cache file.
For our template engine, you can now add any required extensions, change behavior, operators, and add functions and filters. The class below, for example, allows using any php-functions in templates:
3. Links for static and dynamic paths in Phalcon \ Mvc \ Url
Now you can specify different paths for links leading to static files: to pictures or, for example, js files and for links to pages. This feature will be especially relevant when using a CDN.
$di['url'] = function(){ $url = new Phalcon\Mvc\Url(); // ​ URI mod-rewrite $url->setBaseUri('/index.php?_url='); // ​ ​ URI CSS/Javascript/Images $url->setStaticUri('/static/'); return $url; };
4. Phalcon \ Mvc \ View \ Simple
The component is a lighter alternative to Phalcon \ Mvc \ View, without support for a hierarchy of patterns. It will be relevant for use in micro-applications and get views as a string.
// ​ ​View service $di['view'] = function() { $view = new Phalcon\Mvc\View\Simple(); $view->setViewsDir(APP_PATH . '/views/'); return $view; };
Our ORM has begun to maintain a many-to-many relationship. This allows you to establish direct relationships between the two models using a third intermediate model:
classArtistsextendsPhalcon\Mvc\Model{ public $id; public $name; publicfunctioninitialize(){ $this->hasManyToMany( 'id', 'ArtistsSongs', 'artists_id', 'songs_id', 'Songs', 'id' ); } }
Songs of performers can be obtained through the alias of the relationship:
With many-to-many relationships you can work in PHQL (this is an add-on for SQL, which simplifies the use of models and the construction of sql queries):
$phql = 'SELECT Artists.name, Songs.name FROM Artists JOIN Songs WHERE Artists.genre = "Trip-Hop"'; $result = $this->modelsManager->query($phql);
Linked data can be added immediately when creating a model, all necessary intermediate binding records will also be created automatically:
We taught Phalcon \ Assets component not only to flexibly manage static resources, group and filter them, but also compress JS / CSS (minify). For such demanding work, ready-made Jsmin solutions from Douglas Crockford and CSSMin from Ryan Day were used.
We diligently avoid using any static methods, they still work, but using them is not advisable. The Phalcon \ Tag component is now available as a service in DI \ FactoryDefault. Instead:
Phalcon\Tag is now a service in DI\FactoryDefault​. So instead of doing this:
Worth using:
$this->tag->setDefault('name', $robot->name);
12. Macros in Volt
Work with macros has just begun, more will continue:
Prior to version 1.1.0, a warning occurred when passing an incorrect number of parameters to methods. Starting from version 1.2.0, in such situations, a BadMethodCallException will be created with the ability to track exactly where the error occurred:
<?php $e = new Phalcon\Escaper(); $e->escapeCss('a {}', 1, 2, 3);
Will be displayed:
Fatal error: Uncaught exception'BadMethodCallException' with message 'Wrong number of parameters' in test.php:4 Stack trace: #0 test.php(4): Phalcon\Escaper->escapeCss('a {}', 1, 2, 3) #1 {main}
14. Debug Component
The Phalcon \ Debug component forms a debugging stack, allowing the developer to trace where something went wrong. The data are decorated in a structured form. For the component to work, you must remove the try / catch blocks in the start file and specify it at the beginning:
(new Phalcon\Debug)->listen();
We have prepared a small screencast with a demonstration of the component:
There are some more important innovations:
Nested transactions in Phalcon \ Db, work with multiple connections is supported
XCache / Igbinary caching adapter support for Cache / Annotations / ORM-MetaData
A complete list of changes is available at CHANGELOG .
Download
You can build a new version on GitHub , or download ready-made DLL libraries for Windows. Ready-made builds are also available for some linux systems . Documentation is also updated.
New motto
For a long time we worked under the motto “The fastest PHP Framework”, fully complying with it and maintaining the speed of Phalcon at the maximum. We optimized everything we could and looked for any opportunities to save memory and reduce overhead. But speed is not our only priority. From version to version, we tried to make Phalcon even more convenient and include the most useful features. This allowed the project to grow into one of the fastest and most functional products in the open source world. Moving forward, we decided to change our motto for more accurate positioning of Phalcon. From version 1.2.0 we work under the slogan “The best balance of speed and functionality”. Our primary goal is to maintain the optimal balance between the speed of the framework and the functionality it provides. We really want to be not only the fastest framework for PHP, but also the most optimal in terms of speed and functionality.
Acknowledgments
We want to thank all the community members, developers, voting for new functions and helping with their implementation and testing. Anyone who helps with testing and improving documentation. Thanks to everyone who helps develop Phalcon and participates in community life. Thanks you!