I am trying to integrate with MongoDB but I am getting error. This is what i did: In my DI file:
use Phalcon\Mvc\Collection\Manager as CollectionManager;
use Phalcon\Db\Adapter\MongoDB\Client;
//connect to Mongo
$di->set(
"mongo",
function () use ($config) {
$mongo = new MongoClient(
"mongodb://" . $config->mongo->username . ":". $config->mongo->password . "@" . $config->mongo->host . ":" . $config->mongo->port
);
$mongo->selectDB('test');
},
);
// Collection Manager is required for MongoDB
$di->set('collectionManager', function(){
return new CollectionManager();
});
I created a model:
namespace App\Models;
use Phalcon\Mvc\Collection;
class APILog extends Collection
{
public $id;
public $ip;
public $timestamp;
public $api;
public function initialize()
{
$this->setSource("logs");
}
public function showdoc($id)
{
print $id;
}
}
In my service file i tried to access this APILog class: use App\Models\Log; public function writeLog($something){ $k = new APILog($something); }
This gives me 500 error.
My folder structure goes like this:
/
/config
config.php
routes.php
loader.php
di.php
/controllers
mycontroller.php
Abstractexception.php
Abstratcontroller.php #this extends \Phalcon\DI\Injectable
/models
mymodel.php
APILog.php
/services
AbstractService.php #this extends \Phalcon\DI\Injectable
myservice.php
Can anyone please suggest what i am missing here. I need to store the Log reports.