Dear Team,
When could we expect MongoDB support in Phalcon 3 + PHP7? I read the other discussions but I could not find any date or current status.
Thanks in advance.
|
Dec '18 |
7 |
1947 |
1 |
Dear Team,
When could we expect MongoDB support in Phalcon 3 + PHP7? I read the other discussions but I could not find any date or current status.
Thanks in advance.
Considering how difficult it was to find information on the internet, let me share my experience. First of all, Sanketh, I feel your pain. The lack of compatibility between the technologies involved (PHP 5->7, Phalcon 2->3, MongoClient->MongoDB) made this a painful and confusing process. MongoClient is not compatible with PHP7, MongoDB is not backward-compatible, the doc of the incubator class recommended by Serghei specifically points to Phalcon 2.1. Some other article said that Phalcon 2.1 broke compatibility and would thus be renamed 3.0 though, so that might be a technically accurate yet misleading documentation. Anyway, the incubator class pointed out by Serghei seemed to do the trick for me.
Add the Incubator library - in my case, I ran the following Bash command in the library folder:
$ git clone -b 3.1.x https://github.com/phalcon/incubator.git
Register the Incubator in the class autoloader - in my case, I added one line in the bootstrap:
$loader->registerNamespaces([
/* other libs */
'Phalcon' => BASE_DIR . '/' . $config->application->librariesDir . 'incubator/Library/Phalcon/'
] )->register();
Replace the old Mongo library with the Incubator one - in my case, in the $config['di']->set('mongo') function:
$mongoClient = new \Phalcon\Db\Adapter\MongoDB\Client(); // was: new \MongoClient();
return $mongoClient->selectDatabase($config->database->name); // unchanged
That got me a "Call to undefined method rewind" until I changed my models from extends \Phalcon\Mvc\Collection
to extends \Phalcon\Mvc\MongoCollection
. With that, my app seemed to work as normal.
I hope this will be useful to someone.
Is new model class from the incubator 100% compatible with old one? They look similar but I couldn't find no official remark if new class is compatible and simple changing of parent class won't break anything up.
Considering how difficult it was to find information on the internet, let me share my experience. First of all, Sanketh, I feel your pain. The lack of compatibility between the technologies involved (PHP 5->7, Phalcon 2->3, MongoClient->MongoDB) made this a painful and confusing process. MongoClient is not compatible with PHP7, MongoDB is not backward-compatible, the doc of the incubator class recommended by Serghei specifically points to Phalcon 2.1. Some other article said that Phalcon 2.1 broke compatibility and would thus be renamed 3.0 though, so that might be a technically accurate yet misleading documentation. Anyway, the incubator class pointed out by Serghei seemed to do the trick for me.
Add the Incubator library - in my case, I ran the following Bash command in the library folder:
$ git clone -b 3.1.x https://github.com/phalcon/incubator.git
Register the Incubator in the class autoloader - in my case, I added one line in the bootstrap:
$loader->registerNamespaces([ /* other libs */ 'Phalcon' => BASE_DIR . '/' . $config->application->librariesDir . 'incubator/Library/Phalcon/' ] )->register();
Replace the old Mongo library with the Incubator one - in my case, in the $config['di']->set('mongo') function:
$mongoClient = new \Phalcon\Db\Adapter\MongoDB\Client(); // was: new \MongoClient(); return $mongoClient->selectDatabase($config->database->name); // unchanged
That got me a "Call to undefined method rewind" until I changed my models from
extends \Phalcon\Mvc\Collection
toextends \Phalcon\Mvc\MongoCollection
. With that, my app seemed to work as normal.I hope this will be useful to someone.
It was a great help for me! But now I have a new error I can't resolve:
Fatal error: Uncaught Error: Class 'MongoDB\Manager' not found
my code is
$di->setShared('collectionManager', function () {
return new Manager();
});
Considering how difficult it was to find information on the internet, let me share my experience. First of all, Sanketh, I feel your pain. The lack of compatibility between the technologies involved (PHP 5->7, Phalcon 2->3, MongoClient->MongoDB) made this a painful and confusing process. MongoClient is not compatible with PHP7, MongoDB is not backward-compatible, the doc of the incubator class recommended by Serghei specifically points to Phalcon 2.1. Some other article said that Phalcon 2.1 broke compatibility and would thus be renamed 3.0 though, so that might be a technically accurate yet misleading documentation. Anyway, the incubator class pointed out by Serghei seemed to do the trick for me.
Add the Incubator library - in my case, I ran the following Bash command in the library folder:
$ git clone -b 3.1.x https://github.com/phalcon/incubator.git
Register the Incubator in the class autoloader - in my case, I added one line in the bootstrap:
$loader->registerNamespaces([ /* other libs */ 'Phalcon' => BASE_DIR . '/' . $config->application->librariesDir . 'incubator/Library/Phalcon/' ] )->register();
Replace the old Mongo library with the Incubator one - in my case, in the $config['di']->set('mongo') function:
$mongoClient = new \Phalcon\Db\Adapter\MongoDB\Client(); // was: new \MongoClient(); return $mongoClient->selectDatabase($config->database->name); // unchanged
That got me a "Call to undefined method rewind" until I changed my models from
extends \Phalcon\Mvc\Collection
toextends \Phalcon\Mvc\MongoCollection
. With that, my app seemed to work as normal.I hope this will be useful to someone.
My code does a as follows instead:
return new \Phalcon\Mvc\Collection\Manager();
Maybe you can try that?
It was a great help for me! But now I have a new error I can't resolve:
Fatal error: Uncaught Error: Class 'MongoDB\Manager' not found
my code is
$di->setShared('collectionManager', function () { return new Manager(); });