📜 ⬆️ ⬇️

Phalcon 1.1 beta

Go
After the successful release of the PHP framework Phalcon 1.0 , the development team continues to work on its development. In this article I want to highlight the most interesting features presented in version 1.1.0 of BETA





Pagination in Query Builder (QueryBuilder)


Previously, the paginator was available only for the output of data from the Model and native arrays. Now pagination can be used to output data of an arbitrary query through the QueryBuilder constructor, which uses the LIMIT / OFFSET SQL statements. It will be useful for displaying large data sets.
')
use Phalcon\Paginator\Adapter\QueryBuilder; $builder = $this->modelsManager->createBuilder() ->columns('id, name') ->from('Robots') ->orderBy('name'); $paginator = new Paginator(array( "builder" => $builder, "limit" => 10, "page" => 1 )); $page = $paginator->getPaginate(); 



Queue Server Beanstalkd


A simple client for the Beanstalkd queue server is now part of the framework.

 //    $queue = new Phalcon\Queue\Beanstalk(array( 'host' => '192.168.0.21' )); //     ( ) $queue->put(array('proccessVideo' => 4871)); //     ( ) $queue->put( array('proccessVideo' => 4871), array('priority' => 250, 'delay' => 10, 'ttr' => 3600) ); while (($job = $queue->peekReady()) !== false) { $message = $job->getBody(); var_dump($message); $job->delete(); } 



Encryption


This version of Phalcon has added a PHP-based mcrypt encryption class .

 //     $encryption = new Phalcon\Crypt(); $key = 'le password'; $text = 'This is a secret text'; $encrypted = $encryption->encrypt($text, $key); echo $encryption->decrypt($encrypted, $key); 



Assets Management


With this component, you can easily manage static resources such as CSS and Javascript.

 //      CSS $this->assets ->addCss('css/style.css') ->addCss('css/index.css'); //  - js- $this->assets ->addJs('js/jquery.js') ->addJs('js/bootstrap.min.js'); 


and then show them in the template
 <html> <head> <title>Some amazing website</title> <?php $this->assets->outputCss() ?> </head> <body> <!-- ... --> <?php $this->assets->outputJs() ?> </body> </html> 



Exception mode for ORM validators


During data validation, in the process of creating / updating a database record, the save () / create () / update () methods return a boolean value, i.e. FALSE if one of the parameters failed validation. Now this behavior can be changed and an exception is thrown:

 use Phalcon\Mvc\Model\ValidationFailed; try { $robot = new Robots(); $robot->name = 'Bender'; $robot->save(); } catch (ValidationFailed $e) { echo 'Reason: ', $e->getMessage(); } 



Routing by host name


In the routing rules, you can now specify the host name

 $router = new Phalcon\Mvc\Router(); $router->addGet('/api/robots', array( 'module' => 'api', 'controller' => 'robots', 'action' => 'index' ))->setHostName('api.phalconphp.com'); 


You can also use a route group.
 $group = new Phalcon\Mvc\Router(); $group->setHostName('api.phalconphp.com'); $groop->addGet('/api/robots', array( 'module' => 'api', 'controller' => 'robots', 'action' => 'index' )); $groop->addGet('/api/robots/{id}', array( 'module' => 'api', 'controller' => 'robots', 'action' => 'show' )); $router->mount($group); 



Using Controllers in Mvc \ Micro Applications


For better organization of the micro-application structure in the new version of Phalcon, controllers can be specified as a request handler (previously only callable values ​​could be used).

 $collection = new Phalcon\Mvc\Micro\Collection(); //   $collection ->setPrefix('/posts') ->setHandler(new PostsController()); //   $collection ->setPrefix('/posts') ->setHandler('PostsController', true); $collection->get('/', 'index'); $collection->get('/edit/{id}', 'edit'); $collection->delete('/delete/{id}', 'delete'); $app->mount($collection); 



Afterword


Phalcon 1.1.0 includes other changes and bug fixes. A complete list of changes can be viewed in CHANGELOG , as well as read the documentation for this version of the framework.

If you have not personally tested Phalcon performance so far, you can install it right now.
 git clone http://github.com/phalcon/cphalcon cd build git checkout 1.1.0 sudo ./install 

while Windows users just need to install the DLL from the download page

Developers are invited to discuss this release on the forum (which, by the way, is also written in Phalcon) and Stack Overflow .
If you catch a bug, Github will gladly accept a pull request or a failing test.


Help the community by voting for Phalcon support in cPanel


Phalcon developers are proposing to add framework support to the cPanel web hosting control panel.

If Phalcon becomes an accessible extension for cPanel clients, it will not only increase the framework’s popularity, but also benefit developers, hosting companies, and later end users, because Phalcon is written in C, which means it consumes less memory and creates less load on server in comparison with analogues written in PHP.

You can support the development of the framework by voting for the feature-request on the cPanel website:
http://features.cpanel.net/responses/add-support-for-phalconphp-extension-apache-php



Sources:


PS The text is translated and prepared by agent_j , which, due to certain reasons, cannot place it on its own.

Source: https://habr.com/ru/post/177691/


All Articles