I'm trying to get settings for a website from MongoDB via PhalconPHP, using an Phalcon\Mvc\Model. Here's my model:
namespace CMS4\Common\Model;
use Phalcon\Mvc\Model as MongoDocument;
class Settings extends MongoDocument
{
/**
*
* @var \MongoId
*/
protected $id;
/**
*
* @var int
*/
public $websiteId;
/**
*
* @var array[]
*/
public $leUserConfig;
public function initialize()
{
$this->setConnectionService('mongo');
}
/**
* By default that model will refer to `WebsiteSettings`, wherefore getSource is implemented
* @return string
*/
public function getSource()
{
return 'WebsiteSettings';
}
}
However, calling it via $test = Settings::find();
I get the following RuntimeException:
Call to undefined method ::gettype()
I guess this is used somewhere internally by PhalconPHP, but a quick glance at the source code led me nowhere. I'm out of ideas, please advise. If I need to provide more information, just say so.
When querying a Mongo Collection with the Phalcon Framework, you should be using the ODM instead of the ORM, and as such, using the Collection classes instead of the Model classes.
You can find out more on how to set this up and use these features here: https://docs.phalconphp.com/en/3.2/db-odm