Using Phalcon 2.0.11 with a Mongo database, ::find returns arrays and not objects as I expected.
In the mongo shell I create a document with a few objects, e.g.
>db.flints.insert({name:"test", "stuff" : { "enabled" : true, "info" : { "description" : "Descrip" }}})
WriteResult({ "nInserted" : 1 })
> db.flints.find({name:"test"})
{ "_id" : ObjectId("573dccf0f6a6ce56e20ebe56"), "name" : "test", "stuff" : { "enabled" : true, "info" : { "description" : "Descrip" } } }
However using the following code snippet the properties enabled, info, description etc. are only accessible via array notation.
$flint = Flints::findFirst(array(array('name'=>'test')));
echo $flint->stuff->info->description; // PHP Notice: Trying to get property of non-object
echo $flint->stuff['info']['description']; // Prints 'Descrip'
$flint->stuff->enabled = false; // PHP Warning: Attempt to assign property of non-object
$flint->stuff['enabled'] = false;
$flint->save();
Is there a way to access the returned document by using properties instead of arrays ?
Thanks.
My model, and services,
use Phalcon\Mvc\Collection;
class Flints extends Collection { }
$di->setShared('mongo', function () use ($config) {
$mongo = new MongoClient();
return $mongo->selectDB("test");
});
$di->set('collectionManager', function() {
return new Phalcon\Mvc\Collection\Manager();
}, true);