Blog and News

Hello everyone!

It has been a while since we last posted an update regarding Phalcon. We apologize for this. As you all know this is an open source project and all of us in the community contribute using our free time and enthusiasm for the project. However sometimes, other tasks need more immediate attention such as work and family.

Workload

Due to the team's increased workload (family/work), we reached out to a C developer that can help us with some Zephir and Phalcon related bugs. We are working on compensation at the moment as well as the priority of bugs that need to be squashed so that we can move the project forward. We are going to use the funds that all of our supporters have graciously donated to the project in OpenCollective. We are very careful about those funds and only use them when needed, so we have decided that this would be a great way to help the project.

Github issues

Again, related to the workload, we have a number of Github issues that have been opened and are stale. Some of those issues have been open for months and are no longer valid because either they have been fixed but never updated and some have never been followed up (requesting information/examples).

In an effort to clean up our issue list as well as be able to focus on valid issues, we have installed the stale bot in Github, which will mark issues that have not been active for the last 90 days as stale. This process is automated.

This new bot will allow us to shorten the list of issues and focus in fixing and closing valid issues from the list.

NOTE: The bot is not part of any Artificial Intelligence code, so it is going to close issues that have been inactive the last 90 days. This could very well close valid issues that we have not had the time to address yet. If your issue has been automatically closed and it is valid, please help us by reopening it or creating a new one.

We would like to once more thank our contributors as well as sponsors for helping us make Phalcon awesome!

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Hello everyone!

Phalcon 3.3.1 has been released, addressing some bugs.

The release tag can be found here: 3.3.1

Changelog

  • Fixed a boolean logic error in the CSS minifier and a corresponding unit test so that whitespace is stripped #13200
  • Fixed default Volt filter #13242, #13244
  • Fixed Phalcon\Validation\Validator\Date to return code in validation message

Update/Upgrade

Phalcon 3.3.1 can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

Note that running the installation script will replace any version of Phalcon installed before.

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Our packaging system not longer supports Ubuntu 15.10 due to difficulties installing dependencies, updates and major security patches. Ubuntu 15.10 reached its end of life in July 28, 2016. We strongly recommend you upgrade your installation. If you cannot, you can always build the latest stable version of Phalcon from the source code.
NOTE: Windows DLLs are now available in our Github Release page.

We encourage existing Phalcon 3 users to update to this version and as always a big thank you to our contributors!

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

image

The Phalcon Team wishes all of our friends, contributors, developers and users of the framework a Merry Christmas!. We hope that the new year will bring health and happiness to you and your loved ones!

As a small gift for this holiday/celebration, we are releasing Phalcon 3.3.0.

This release concentrated on support for PHP 7.2, new features and fixing some bugs,

A huge thank you to all of our contributors and the community!!

The release tag can be found here: 3.3.0

Changelog

  • Added support of PHP 7.2 and initial support of PHP 7.3
  • Added support for switch/case syntax to the Volt Engine #13107
  • Added Phalcon\Logger\Adapter\Blackhole #13074
  • Added Phalcon\Http\Request::hasHeader to check if certain header exists
  • Added support of 103 (Early Hint) HTTP status code
  • Added router:beforeMount event to Router::mount #13158
  • Added Phalcon\Mvc\Application::sendHeadersOnHandleRequest to enable or disable sending headers by each request handling #13101
  • Added Phalcon\Mvc\Application::sendCookiesOnHandleRequest to enable or disable sending cookies by each request handling #13101
  • Added ability to use PDO option aliases on database connect #13010
  • Added Phalcon\Mvc\Model\MetaData\Apcu #13078
  • Added ability to use string(file path) as a argument in Phalcon\Config\Factory::load()
  • Added Phalcon\Mvc\Mico\Collection::mapVia to map routes via methods
  • Added Phalcon\Mvc\Model::setOldSnapshotData to set old snapshot data separately to current snapshot data
  • Added Phalcon\Http\Response::removeHeader to remove specific header from response
  • Added Phalcon\Mvc\Query::setTransaction to enable an override transaction #13226
  • Fixed Phalcon\Mvc\Model\Query\Builder::getPhql to correct generate PHQL in argument's array when using order DESC or ASC #11827
  • Fixed Phalcon\Db\Dialect\Postgresql::createTable to produce valid SQL for table definition with BOOLEAN types #13132
  • Fixed Phalcon\Db\Dialect\Postgresql::_castDefault to return correct value for BOOLEAN type #13132, phalcon/phalcon-devtools#1118
  • Fixed Phalcon\Mvc\Model::_doLowInsert to correct save snapshot on creation/save identityless models #13166
  • Fixed Phalcon\Mvc\Model::_doLowUpdate to correctly work with Phalcon\Db\RawValue #13170
  • Fixed Phalcon\Mvc\Model::allowEmptyStringValues to correct works with saving empty string values when DEFAULT not set in SQL
  • Fixed Phalcon\Mvc\Model\Behavior\SoftDelete to correctly update snapshots after deleting item
  • Fixed Phalcon\Mvc\Model to set old snapshot when no fields are changed when dynamic update is enabled
  • Fixed Phalcon\Acl\Adapter\Memory::isAllowed to properly pass role and resource objects to custom function if they are objects of the same class
  • Changed Phalcon\Mvc\Model to allow to pass a transaction within the query context #13226

Highlights

The most notable additions are support for switch/case syntax in Volt, hasHeader in Request and the addition of the router:beforeMount event.

switch/case

You can now use the switch statement in Volt

{% switch foo %}
    {% case 0 %}
    {% case 1 %}
    {% case 2 %}
        "foo" is less than 3 but not negative
        {% break %}
    {% case 3 %}
        "foo" is 3
        {% break %}
    {% default %}
        "foo" is {{ foo }}
{% endswitch %}

The switch statement executes statement by statement, therefore the break statement is necessary in some cases. Any output (including whitespace) between a switch statement and the first case will result in a syntax error. Empty lines and whitespaces can therefore be cleared to reduce the number of errors see here.

case without switch

{% case EXPRESSION %}

Will throw Fatal error: Uncaught Phalcon\Mvc\View\Exception: Unexpected CASE.

switch without endswitch

{% switch EXPRESSION %}
Will throw `Fatal error: Uncaught Phalcon\Mvc\View\Exception: Syntax error, unexpected EOF in ..., there is a 'switch' block without 'endswitch'`.

default without switch

{% default %}

Will not throw an error because default is a reserved word for filters like {{ EXPRESSION | default(VALUE) }} but in this case the expression will only output an empty char '' .

nested switch

{% switch EXPRESSION %}
  {% switch EXPRESSION %}
  {% endswitch %}
{% endswitch %}

Will throw Fatal error: Uncaught Phalcon\Mvc\View\Exception: A nested switch detected. There is no nested switch-case statements support in ... on line ....

a switch without an expression

{% switch %}
  {% case EXPRESSION %}
      {% break %}
{% endswitch %}

Will throw Fatal error: Uncaught Phalcon\Mvc\View\Exception: Syntax error, unexpected token %} in ... on line ....

hasHeader in Phalcon\Http\Request

You can now use the hasHeader method, to check if a header has been set in the incoming request.

if ($request->hasHeader('myheader')) {
    echo 'Yay! Header was set!!';
}

router:beforeMount

Sometimes it is necessary to attach some logic to our application, before the routes are mounted in our Router object. The beforeMount event is perfect in these cases. You can now use it if your application requirements dictate so.

Update/Upgrade

Phalcon 3.3.0 can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

Note that running the installation script will replace any version of Phalcon installed before.

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Our packaging system not longer supports Ubuntu 15.10 due to difficulties installing dependencies, updates and major security patches. Ubuntu 15.10 reached its end of life in July 28, 2016. We strongly recommend you upgrade your installation. If you cannot, you can always build the latest stable version of Phalcon from the source code.
NOTE: Windows DLLs are now available in our Github Release page.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Hello everyone!!!

We are releasing Phalcon 3.2.3 today, addressing several bugs.

Release

The release tag can be found here: 3.2.3. The Windows DLLs are in the releases Github page.

Changelog

  • Fixed Phalcon\Mvc\Model\Query::_executeSelect threw RuntimeException, if db:beforeQuery() returned false
  • Internal cookies property is now always an array #12978
  • Fixed Phalcon\Validation\Validator\File::validate to work properly with parameter message #12947
  • Fixed Phalcon\Mvc\View::render to render a view with params #13046
  • Fixed Phalcon\Mvc\Model\Manager::getRelationRecords to work properly with provided columns #12972
  • Mark as deprecated no longer used Phalcon\Mvc\Model\Query\Builder::$_with parameter #13023
  • Fixed Phalcon\Dispatcher::dispatch to ensure proper flow for all forward/exception/dispatch event hooks #12931

Update/Upgrade

Phalcon 3.2.3 can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

Note that running the installation script will replace any version of Phalcon installed before.

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Our packaging system not longer supports Ubuntu 15.10 due to difficulties installing dependencies, updates and major security patches. Ubuntu 15.10 reached its end of life in July 28, 2016. We strongly suggest you upgrade your installation. If you cannot, you can always build the latest stable version of Phalcon from the source code.
NOTE: Windows DLLs are now available in our Github Release page.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Hello everyone!!!

We are releasing Phalcon 3.2.2 today, addressing several bugs.

Release

The release tag can be found here: 3.2.2. The Windows DLLs are in the releases Github page.

Changelog

  • Fixed Phalcon\Db\Adapter\Pdo\Postgresql::describeColumns to work properly with DOUBLE PRECISION and REAL data types #12842
  • Fixed Phalcon\Paginator\Adapter\QueryBuilder::getPaginate to use the db connection service of the model #12957
  • Fixed Phalcon\Paginator\Adapter\QueryBuilder::getPaginate to escape reserved words #12950
  • Fixed Phalcon\Dispatcher::dispatch to correct forward with the modified action suffix #12988
  • Fixed Phalcon\Forms\Element::_construct to prevent create form element with empty name #12954

Update/Upgrade

Phalcon 3.2.2 can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

Note that running the installation script will replace any version of Phalcon installed before.

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Windows DLLs are now available in our Github Release page.
NOTE: PackageCloud (linux distributions) will be updated tomorrow 2017-08-14.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Hello everyone!!

Often we get queries/requests on how someone can help with the documentation, and how they can set up the docs application on their local machine so as to see changes immediately on their screen before issuing a pull request with their changes.

This blog post outlines how to set up our docs app and how you can help with the documentation effort.

Overview

Our documentation is split into two repositories:

  • Docs App. This repo contains the application that handles our documentation (templates, CSS, etc.).
  • Docs. This repo contains the actual articles that are shown on screen (content).

These repositories have been set up to work together to offer an easy way to set up and maintain the documentation.

The docs repository has also been integrated with Crowdin, which handles all the translation efforts of our documentation.

Setup

So you want to set up the docs application to have the documents application running on your local machine. Great! The steps are:

  • Fork the docs-app repository
  • Fork the docs repository
  • Clone the docs-app to your machine.
  • Install nanobox if you don't have it
  • Setup the .env file
  • Setup the app using nanobox
  • Run the deploy script
  • Run the app with nanobox
  • Launch the app on your browser :)

Fork the repositories

If you haven't done so already, fork the repositories from the phalcon github organization page https://github.com/phalcon. You will need the docs-app and docs repositories.

Clone the docs-app repository

In a suitable location on your machine clone the docs-app repository (the fork)

$ git clone [email protected]:niden/docs-app
NOTE Your repository URL will be different than the above command

Install nanobox

If you haven't done so already, visit nanobox.io and download and install the application. It will ask you some basic questions (usually we use Docker as the engine instead of Virtualbox) as part of its setup. If you don't meet the following requirements you should use VirtualBox.

Docker Requirements

Setup the .env file

In the docs-app folder (or wherever you have cloned the docs-app repository), make a copy of the .env.example file and rename it to .env. Open the file and edit:

  • APP_URL entry with a local domain. In this example we use docs.phalcon.ld.
  • DOCS_REPO entry to your fork of the docs repo. For example it will be something like this:
[email protected]:niden/docs

Setup the app using nanobox

In your folder (where you cloned docs-app) run the following command in a terminal:

$ nanobox run

After a while you will see something like this:

$ nanobox run
Preparing environment :

docs-app (local) :
...

Preparing environment :
...

Building dev environment :
  ✓ Starting docker container
  ✓ Configuring

      **
   *********
***************   Your command will run in an isolated Linux container
:: ********* ::   Code changes in either the container or desktop are mirrored
" ::: *** ::: "   ------------------------------------------------------------
  ""  :::  ""     If you run a server, access it at >> 172.18.0.4
    "" " ""
       "

Once nanobox finishes its tasks, you will be "inside" the container. Your prompt will be:

/app $

Run the deploy script

In the same terminal, (root folder of docs-app) run the deploy script

$ ./deploy

This script will start cloning the docs repository branches needed under the ./docs folder of your docs-app application (mind boggling - too many docs! :D). The output on the terminal will provide information about the process.

Type exit to exit the container.

Run the following command to create a hosts entry for your environment so that you can use the local domain:

$ nanobox dns add local docs.phalcon.ld

This command will be different in your system, depending on the name you chose for your local domain.

Run the app with nanobox

Run the following command:

$ nanobox run php-server

Launch the app in your browser

Open the http://docs.phalcon.ld URL in your browser and voila!!!

Modifications

If you wish to make changes to the application (docs-app), stylesheets or layout, feel free to do so and issue a pull request in the docs-app Phalcon repository.

You can also help with some of the English text located in the en folder under each version folder (docs/3.2/en, docs/3.1/en, etc.). These changes will be sent to the docs Phalcon repository.

Changes to a docs file (markdown) in any language other than English will not be accepted

Translations

For languages other than English, you will need to use Crowdin Project for the documentation:

https://crowdin.com/project/phalcon-documentation

The translated strings will be brought into the documentation via pull requests from Crowdin.

Enjoy!!

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Hello community!!

We are releasing Phalcon 3.2.1 today, addressing several bugs.

Release

The release tag can be found here: 3.2.1. The Windows DLLs are in the releases Github page.

Changelog

  • Added Phalcon\Db\Dialect\Mysql::getForeignKeyChecks to generate a SQL to check the foreign key settings #2604, phalcon/phalcon-devtools#556
  • Fixed inconsistent behaviour of Phalcon\Config::merge across minor version of PHP7 #12779
  • Fixed visibility of Phalcon\Mvc\Model\Query\Builder methods: _conditionNotIn, _conditionIn, _conditionNotBetween and _conditionBetween to allow 3rd party libraries extend it
  • Fixed Phalcon\Assets\Manager::output, implemented missing resource type filtering for mixed resource collections #2408
  • Fixed Phalcon\Http\Response::getStatusCode to return (int) HTTP code only, instead of full string #12895
  • Fixed Phalcon\Db\Dialect\Postgresql::addForeignKey for proper creating the foreign key without a name
  • Fixed Phalcon\Cache\Backend\Apcu::flush to use APCu instead APC #12934
  • Fixed Phalcon\Db\Adapter\Pdo\Mysql::addForeignKey for proper creating the foreign key with a desired key name #2604, phalcon/phalcon-devtools#556
  • Fixed Phalcon\Db\Dialect\Mysql::addForeignKey to generate correct SQL #2604, phalcon/phalcon-devtools#556

Update/Upgrade

Phalcon 3.2.1 can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

Note that running the installation script will replace any version of Phalcon installed before.

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Windows DLLs are now available in our Github Release page.
NOTE: PackageCloud (linux distributions) will be updated within an hour of this blog post.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000
TLDR; We released new docs, messed up, fixed it, enhancing it now, new translation platform.

Hello everyone!

Last week we have released a new Phalcon version 3.2 as well as our new documentation.

Well, that did not go as planned, since we ended up with a lot of angry developers, because the old documentation was not available (at least temporarily) and also we had a lot of broken links in search engines.

We tried to rectify the issue as fast as possible so we have several redirects that point old links to where they are supposed to. We have also created https://olddocs.phalconphp.com/ which contains all the old documents. That site will remain active for quite a long time, so you don't need to worry if you are behind in upgrating to a later version of Phalcon. :)

Changes

The biggest chance that we have been working on the last few months, was to change all of our documents to the markdown format from reStructured Text. Although this was not a huge task, it was time consuming. We also addressed the issue of broken links, image files left over from old documents etc.

Once that process was completed, we tied up the documentation to Crowdin in order to allow contributors translate our documentation in different languages. As with any new technology, we had some setup issues that were only identified after we released 3.2.

Note that there are indeed some CSS issues with the documentation that we expect to have them resolved by next week.

Docs

The docs repository had to be split into two. One (docs-app) would contain the Phalcon application that handles the documentation, contains the stylesheets etc. while the second one (docs) the one that contains all the markdown documents with the contents of our documentation.

The Crowdin team was simply amazing during this process. Not only have they fixed stuff we broke in our integration, but they also guided us on how to create an easy to maintain workflow so that we can easily release our new documentation, translated, whenever we release a new version.

You can find our docs-app repository here and the docs repository here.

For each release we will have a branch in the docs repository that will contain the documentation for that specific release with the added functionality.

The beauty of using Crowdin is that it identifies identical strings of text throughout branches. As a result if contributors say have translated all of the documents in Spanish for 3.2, when we release 3.3 only the changed text will appear as not translated.

We have to thank once again Crowdin for their tremendous help with our implementation and for hosting our translations/documents in their platform. We highly recommend their service:

Crowdin Logo

Phalcon Documentation: https://crowdin.com/project/phalcon-documentation

Website

We have also ported all of the translations from Transifex to Crowdin so that we can use only one platform for our translations. The Crowdin project is located here. We made an announcement in Transifex for all translators there, and hopefully we will see everyone migrate to the new platform.

As always any suggestions for new languages or even corrections in our text are more than welcome!

Thank you!

Thank you all for your contributions! You guys rock!

<3 Phalcon Team

References:

01010000011010000110000101101100011000110110111101101110010100000100100001010000

With Phalcon 3.2.0 there were many new features and bugs fixed. Today we will write about most important things you need to know and show some code examples of new features.

Added Factory Adapter loaders #11001

With this feature you can load your services in more simplified way using for example ini file:

[database]
host = TEST_DB_MYSQL_HOST
username = TEST_DB_MYSQL_USER
password = TEST_DB_MYSQL_PASSWD
dbname = TEST_DB_MYSQL_NAME
port = TEST_DB_MYSQL_PORT
charset = TEST_DB_MYSQL_CHARSET
adapter = mysql
<?php

use Phalcon\Config\Adapter\Ini;
use Phalcon\Di;
use Phalcon\Db\Adapter\Pdo\Factory;

$di = new Di();
$config = new Ini('config.ini');

$di->set('config', $config);

$di->set(
    'db', 
    function () {
        return Factory::load($this->config->database);
    }
);

This will properly create your database instance and you can change database adapter to another one if necessary in the ini file anytime without changing your code.

Added ability to sanitize URL to Phalcon\Filter

There were added new sanitize filter - url which allows you to clear your urls. For example:

<?php

use Phalcon\Filter;

$filter     = new Filter();
$wrongUrl   = 'http://juhara��.co�m';
$correctUrl = $filter->sanitize($wrongUrl, 'url');

echo $correctUrl; // displays 'http://juhara.com'

Added Phalcon\Mvc\Model::hasUpdated and Phalcon\Mvc\Model:getUpdatedFields, way to check if fields were updated after create/save/update, Added option to disable snapshot update on create/save using Phalcon\Mvc\Model::setup(['updateSnapshotOnSave' => false]) or phalcon.orm.update_snapshot_on_save = 0 in php.ini

In Phalcon 3.1.0 we changed the behavior of snapshots; they are now updated on model creation/update. This could potentially cause problems to your application if you execute Model::getChangedFields in afterUpdate(), afterSave() or afterCreate(). This change was done to fix other things also (for example dynamic update).

Right now you have two options:

  • change your methods from hasChanged(), getChangedFields(), getSnapshotData() to hasUpdated(), getUpdatedFields(), getOldSnapshotData() or
  • add phalcon.orm.update_snapshot_on_save = 0 to your php.ini to disable snapshot updating on save.
<?php

use Phalcon\Mvc\Model;

class User extends Model
{
  public function initialize()
  {
      $this->keepSnapshots(true);
  }
}

$user       = new User();
$user->name = 'Test User';
$user->create();
var_dump($user->getChangedFields());
$user->login = 'testuser';
var_dump($user->getChangedFields());
$user->update();
var_dump($user->getChangedFields());

On Phalcon 3.0.0 output was:

array(1) {
[0]=>
string(4) "name"
}
array(2) {
[0]=>
string(4) "name"
[1]=>
string(5) "login"
}
array(2) {
[0]=>
string(4) "name"
[1]=>
string(5) "login"
}

On Phalcon 3.1.0 and later it is:

array(0) {
}
array(1) {
[0]=>
string(5) "login"
}
array(0) {
}

Model::getUpdatedFields will properly return updated fields or as mentioned above you can go back to the previous behavior by setting the relevant ini value.

Added support for having option in Phalcon\Paginator\Adapter\QueryBuilder #12111

From now on you can use Phalcon\Mvc\Model\Query\Builder::having and Phalcon\Paginator\Adapter\QueryBuilder.

Let's assume you have such a table stock:

DROP TABLE IF EXISTS `stock`;
CREATE TABLE `stock` (
`id`    INT(11)     NOT NULL,
`name`  VARCHAR(32) NOT NULL,
`stock` INT(11)     NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

LOCK TABLES `stock` WRITE;
INSERT INTO `stock` (`id`, `name`, `stock`) VALUES
(1, 'Apple', 2),
(2, 'Carrot', 6)
(3, 'pear', 0);
UNLOCK TABLES;

ALTER TABLE `stock`
ADD PRIMARY KEY (`id`);

ALTER TABLE `stock`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

And this code:

<?php

use Phalcon\Di\FactoryDefault;
use Phalcon\Paginator\Adapter\QueryBuilder;

class Stock extends Phalcon\Mvc\Model {};

$di            = new FactoryDefault();
$modelsManager = $di->get('modelsManager');
$builder       = $modelsManager
                    ->createBuilder()
                    ->columns('*, COUNT(*) as stock_count')
                    ->from(['Stock' => Stock::class])
                    ->groupBy('name')
                    ->having('SUM(Stock.stock) > 0');

$paginate = (
    new QueryBuilder(
        [
            'builder' => $builder,
            'limit'   => 1,
            'page'    => 2
        ]
    )
)->getPaginate();
var_dump($paginate->total_pages); // now it will return 2, previously it was 3
var_dump($paginate->total_items); // now it will return 2, previously it was 3

Please note:

  • MySQL(and other databases) will need to select all rows and do a count on it.
  • We use groupBy to select columns for those rows.
  • If you don't have groupBy then you need to pass columns option to Phalcon\Paginator\Adapter\QueryBuilder:
<?php

use Phalcon\Di\FactoryDefault;
use Phalcon\Paginator\Adapter\QueryBuilder;

class Stock extends Phalcon\Mvc\Model {};

$di            = new FactoryDefault();
$modelsManager = $di->get('modelsManager');
$builder       = $modelsManager
                    ->createBuilder()
                    ->columns('*, COUNT(*) as stock_count')
                    ->from(['Stock' => Stock::class])
                    ->having('SUM(Stock.stock) > 0');

$paginate = (
    new QueryBuilder(
        [
            'builder' => $builder,
            'limit'   => 1,
            'page'    => 2,
            'columns' => 'id,stock' // this is required in this case
        ]
    )
)->getPaginate();
var_dump($paginate->total_pages); // now it will return 2, previously it was 3
var_dump($paginate->total_items); // now it will return 2, previously it was 3

Added Phalcon\Config::path to get a value using a dot separated path #12221

<?php

use Phalcon\Config;

$config = new Config(
    [
        'test' => [
            'parent' => [
                'property'  => 1,
                'property2' => 'yeah',
            ],
        ],  
    ]
);

echo $config->path('test.parent.property'); // displays 1

Added service provider interface to configure services by context #12783

From now you can move all your $di->set() to classes like this:

<?php

use Phalcon\Di\ServiceProviderInterface;
use Phalcon\DiInterface;
use Phalcon\Di;
use Phalcon\Config\Adapter\Ini;

class SomeServiceProvider implements ServiceProviderInterface
{
    public function register(DiInterface $di)
    {
        $di->set(
            'config', 
            function () {
                return new Ini('config.ini');
            }
        );
    }
}

$di = new Di();
$di->register(new SomeServiceProvider());
var_dump($di->get('config')); // will return properly our config

Added the ability to load services from yaml (Phalcon\Di::loadFromYaml) and php array (Phalcon\Di::loadFromPhp) files, so we can keep the references cleanly separated from code #12784

This feature will let you set your services in yaml files or just in plain php. For example you can load yaml file like this:

config:
  className: \Phalcon\Config
  shared: true
<?php

use Phalcon\Di;

$di = new Di();
$di->loadFromYaml('services.yml');
$di->get('config'); // will properly return config service

Added Phalcon\Cache\Backend\Apcu to introduce pure support of APCu #12098, #11934, Added Phalcon\Annotations\Adapter\Apcu to introduce pure support of APCu #12098

In PHP 7 to use phalcon apc based adapter classes you needed to install apcu and apcu_bc package from pecl. Now in Phalcon 3.2.0 you can switch your *\Apc classes to *\Apcu and remove apcu_bc. Keep in mind that in Phalcon 4 we will most likely remove all *\Apc classes.

Added Phalcon\Mvc\Model\Manager::setModelPrefix and Phalcon\Mvc\Model\Manager::getModelPrefix to introduce tables prefixes #10328

If you want all your tables to have certain prefix and without setting source in all models you can use Phalcon\Mvc\Model\Manager::setModelPrefix:

<?php

use Phalcon\Mvc\Model\Manager;
use Phalcon\Mvc\Model;

class Robots extends Model
{

}

$manager = new Manager();
$manager->setModelPrefix('wp_');
$robots = new Robots(null, null, $manager);
echo $robots->getSource(); // will return wp_robots

Added way to disable setters in Phalcon\Mvc\Model::assign by using Phalcon\Mvc\Model::setup or ini option

Phalcon\Mvc\Model::assign(which is used also when creating/updating/saving model) is always using setters if they exist when have data argument passed, even when it's not needed or not necessary. It can add not needed overhead to your application. From now you can change this behavior by adding phalcon.orm.disable_assign_setters = 1 to your ini file, it will just simply use this->property = value from now on. From Phalcon 4 we will set it to be default behavior.

Added dispatcher::beforeForward event to allow forwarding request to the separated module #121, #12417

With new event you can change module where to forward in easy and clean way:

<?php

use Phalcon\Di;
use Phalcon\Events\Manager;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Events\Event;

$di = new Di();

$modules = [
  'backend' => [
      'className' => 'App\Backend\Bootstrap',
      'path'      => '/app/Modules/Backend/Bootstrap.php',
      'metadata'  => [
          'controllersNamespace' => 'App\Backend\Controllers',
      ],
  ],
];

$manager = new Manager();

$manager->attach(
  'dispatch:beforeForward',
  function (Event $event, Dispatcher $dispatcher, array $forward) use ($modules) {
      $metadata = $modules[$forward['module']]['metadata'];
      $dispatcher->setModuleName($forward['module']);
      $dispatcher->setNamespaceName($metadata['controllersNamespace']);
  }
);

$dispatcher = new Dispatcher();
$dispatcher->setDI($di);
$dispatcher->setEventsManager($manager);
$di->set('dispatcher', $dispatcher);
$dispatcher->forward(
  [
      'module'     => 'backend',
      'controller' => 'posts',
      'action'     => 'index',
  ]
);

echo $dispatcher->getModuleName(); // will display properly 'backend'
Credit to Wojciech Ślawski for the article
01010000011010000110000101101100011000110110111101101110010100000100100001010000

Hello everyone and Happy Father's day!

For our Father's day present, we are extremely happy to announce the release of our newest Phalcon version: 3.2.0.

Our Github issues page has well over 600 issues. However those are mostly New Feature Requests (NFRs), so we started clearing up more and more bugs as well as introducing suggested NFRs. Of course all this would not be feasible without the help of our amazing community: Thank you!

Documentation

Also as part of our goals for Q2, we are releasing our new documentation. We have been working hard to convert all the rst files (reStructuredText) to md (Markdown) and also have a first pass on identifying inconsistencies and enhancing the documentation. Of course a lot more is needed on that, but it will come in future versions.

We are now using Crowdin to help contributors translate our documents. The docs website has been updated but still needs a little bit of love with the stylesheet (coming very soon). Also you will note that the site mentions version 3.1; we will fix that this week coming to ensure that every document is properly versioned in Crowdin.

Our new documentation needs admittedly a little bit of fine tuning in terms of the CSS and the menus. This will be done in the upcoming week. Also, we are going through all the documents and ensuring the content is correct and accurate throughout. Examples and new functionality of new releases will also be added from now on, before we release so that the documents are up to date always.

NOTE: The documentation for previous versions is located here: https://olddocs.phalconphp.com.

Release

The release tag can be found here: 3.2.0. The Windows DLLs are in the releases Github page.

Changelog

  • Phalcon will now trigger E_DEPREACATED by using Phalcon\Mvc\Model\Criteria::addWhere, Phalcon\Debug::getMajorVersion, Phalcon\Dispatcher::setModelBinding, Phalcon\Tag::resetInput, Phalcon\Mvc\Model\Validator::__construct
  • Added Factory Adapter loaders #11001
  • Added ability to sanitize URL to Phalcon\Filter
  • Added missed $type argument to interface Phalcon\Mvc\Model\Query\BuilderInterface::join() to specify type join
  • Added Phalcon\Mvc\Model::hasUpdated and Phalcon\Mvc\Model:getUpdatedFields, way to check if fields were updated after create/save/update
  • Added support for having option in Phalcon\Paginator\Adapter\QueryBuilder #12111
  • Added Phalcon\Config::path to get a value using a dot separated path #12221
  • Added service provider interface to configure services by context #12783
  • Added the ability to load services from yaml (Phalcon\Di::loadFromYaml) and php array (Phalcon\Di::loadFromPhp) files, so we can keep the references cleanly separated from code #12784
  • Added Phalcon\Cache\Backend\Apcu to introduce pure support of APCu #12098, #11934
  • Added Phalcon\Annotations\Adapter\Apcu to introduce pure support of APCu #12098
  • Added option to disable snapshot update on create/save using Phalcon\Mvc\Model::setup(['updateSnapshotOnSave' => false]) or phalcon.orm.update_snapshot_on_save = 0 in php.ini
  • Added Phalcon\Mvc\Model\Manager::setModelPrefix and Phalcon\Mvc\Model\Manager::getModelPrefix to introduce tables prefixes #10328
  • Added methods Phalcon\Mvc\Model\Query\Builder::andHaving, Phalcon\Mvc\Model\Query\Builder::orHaving, Phalcon\Mvc\Model\Query\Builder::betweenHaving, Phalcon\Mvc\Model\Query\Builder::notBetweenHaving, Phalcon\Mvc\Model\Query\Builder::inHaving, Phalcon\Mvc\Model\Query\Builder::notInHaving
  • Added parameters skip_on_insert, skip_on_update and allow_empty_string and fixed a bug for renamed integer columns in Phalcon\Mvc\Model\MetaData\Strategy\Annotations::getMetaData
  • Added way to disable setters in Phalcon\Mvc\Model::assign by using Phalcon\Mvc\Model::setup or ini option
  • Added ability to sanitize special characters to Phalcon\Filter
  • Added a new Phalcon\Mvc\Model\Binder::findBoundModel method. Params fetched from cache are being added to internalCache class property in Phalcon\Mvc\Model\Binder::getParamsFromCache
  • Added Phalcon\Mvc\Model\Criteria::createBuilder to create a query builder from criteria
  • Added dispatcher::beforeForward event to allow forwarding request to the separated module #121, #12417
  • Added Phalcon\Security\Random:base62 to provide the largest value that can safely be used in URLs without needing to take extra characters into consideration #12105
  • Added Phalcon\Assets\ResourceInterface. So now Phalcon\Assets\Inline and Phalcon\Assets\Resource implements ResourceInterface
  • Added Phalcon\Assets\Collection::has to checks whether the resource is added to the collection or not
  • Added Phalcon\Cli\Dispatcher::getOption, Phalcon\Cli\Dispatcher::hasOption and the options as parameter to cli handlers
  • Added Phalcon\Config\Adapter\Grouped to allow usage of multiple configuration files/adapters in a simple format #12884
  • Added DISTINCT type for Phalcon\Text::random
  • Added autopadding feature for Phalcon\Crypt::encryptBase64 and Phalcon\Crypt::decryptBase64 #12490
  • Fixed Dispatcher forwarding when handling exception #11819, #12154
  • Fixed params view scope for PHP 7 #12648
  • Fixed Phalcon\Mvc\Micro::handle to prevent attemps to send response twice #12668
  • Fixed Di::set, Di::setShared to allow pass more than 10 arguments #12299
  • Fixed Phalcon\Mvc\Model\MetaData\Strategy\Annotations::getColumnMaps where only renamed columns where returned if there was one
  • Fixed Phalcon\Mvc\Micro:handle to correctly handle before handlers #10931
  • Fixed Phalcon\Mvc\Micro:handle to correctly handle afterBinding handlers
  • Fixed Phalcon\Mvc\Model::hasChanged to correctly use it with arrays #12669
  • Fixed Phalcon\Mvc\Model\Resultset::delete to return result depending on success #11133
  • Fixed Phalcon\Session\Adapter::destroy to correctly clear the $_SESSION superglobal #12326, #12835
  • Fixed Phalcon\Assets\Collection:add to avoid duplication of resources #10938, #2008
  • Fixed Phalcon\Mvc\View\Engine\Volt::compile to not throw exception in case of absence the file and stat option is true #12849
  • Fixed Phalcon\Mvc\Collection::getReservedAttributes to workaround for PHP 7/7.1 bug with static null when extending class phalcon/incubator#762, phalcon/incubator#760
  • Fixed Phalcon\Cache\Backend\Redis::__construct and Phalcon\Cache\Backend\Redis::_connect to correctly handle the Redis auth option #12736
  • Fixed Phalcon\Mvc\Collection::getReservedAttributes, added missing properties to reserved attributes phalcon/incubator#762, phalcon/incubator#760
  • Fixed Phalcon\Mvc\Router\Annotation::processActionAnnotation to support PATCH request

Update/Upgrade

Phalcon 3.2.0 can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

Note that running the installation script will replace any version of Phalcon installed before.

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Windows DLLs are now available in our Github Release page.
PackageCloud will be updated shortly.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000