Phalcon 1.1 beta


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

the



Pagination in query Builder (QueryBuilder)


Previously, the pager was only available for output Models and native arrays. Now the pagination can be used when the output of an arbitrary query through the QueryBuilder constructor, which uses SQL LIMIT/OFFSET. It will be useful to display large datasets.

the
php 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();



the Beanstalkd queue Server


A simple client for the server queues, Beanstalkd is now part of the framework

the
// connect to server
$queue = new Phalcon\Queue\Beanstalk(array(
'host' = > '192.168.0.21'
));

// Add task to the queue (simple entry)
$queue- > put(array('proccessVideo' = > 4871));

// Add task to the queue (with parameters)
$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


In this version added Phalcon encryption class based on the PHP library mcrypt

the
// Create an instance of the 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

the
// First controller, let's add some CSS
$this->assets
->addCss('css/style.css')
->addCss('css/index.css');

// and a little js-script
$this->assets
->addJs('js/jquery.js')
->addJs('js/bootstrap.min.js');


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

<!-- ... -->

<?php $this->assets->outputJs() ?>
</body>
</html>



Exception for ORM-validator


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

the
php use Phalcon\Mvc\Model\ValidationFailed;

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



the Routing by hostname


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

the
$router = new Phalcon\Mvc\Router();

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


You can also use the route group
the
$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 applications Mvc\Micro


For a better organization of the structure of the micro-apps in the new version of Phalcon as a request handler you can specify the controllers (previously, you could only use a callable value).

the
$collection = new Phalcon\Mvc\Micro\Collection();

// Initialize immediately
$collection
->setPrefix('/posts')
- >setHandler(new PostsController());

// Lazy initialization
$collection
->setPrefix('/posts')
- >setHandler('PostsController', true);

$collection->get('/', 'index');

$collection->get('/edit/{id}', 'edit');

$collection->delete('/delete/{id}', 'delete');

$app- > mount($collection);



PostScript


Phalcon 1.1.0 and includes other changes and bug fixes. Full list of changes can be viewed in CHANGELOG, and read documentation this version of the framework.

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

and Windows users, it is sufficient to install a DLL with download page.

Developers are invited to discuss this release on the forum (which, incidentally, also written in Phalcon) and Stack Overflow.
If you catch the bug, Github happy to accept pull-request or failing test.


the

Help the community by voting for the support of the Phalcon to cPanel


The Phalcon developers propose to add support for the framework in the control panel for web hosting cPanel.

If Phalcon will be available in the extension for customer of cPanel, this will not only increase the popularity of the framework, but will also benefit developers, hosting companies, and subsequently for end users, because Phalcon is written in C, and therefore consumes less memory and creates less load on the server compared to equivalents written in PHP.

To support the development of the framework, you can vote for feature request on the cPanel website:
http://features.cpanel.net/responses/add-support-for-phalconphp-extension-apache-php



Sources:
the

P. S. the Text was translated and prepared by agent_j, which due to certain reasons can't self-host.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Fresh hay from the cow, or 3000 icons submitted!

Knowledge base. Part 2. Freebase: make requests to the Google Knowledge Graph

Group edit the resources (documents) using MIGXDB