Reputation: 1
I have been trying to use Mongodb with CodeIgniter 4 but facing issues.
puppyModel.php -
<?php
namespace App\Models;
use CodeIgniter\Model;
use App\Libraries\Mongo;
class puppyModel{
/**
* @var Mongo
*/
protected $m;
/**
*
*/
public function __construct()
{
$this->m = new Mongo();
}
public function getList(string $collection, array $where = [], array $options = [], array $select = [])
{
return $this->m->options($options)->select($select)->where($where)->find($collection)->toArray();
}
}
?>
Home.php (Controller) -
<?php
namespace App\Controllers;
use CodeIgniter\Controller;
use app\Models\puppyModel;
class Home extends BaseController{
public function index(){
$puppyModel = new puppyModel();
$data1 = $puppyModel->getList();
print_r($data1);
}
}
I am getting this error -
CRITICAL - 2022-02-02 23:58:05 --> Class "app\Models\puppyModel" not found
#0 C:\xampp\htdocs\cimongo\system\CodeIgniter.php(825): App\Controllers\Home->index()
#1 C:\xampp\htdocs\cimongo\system\CodeIgniter.php(412): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Home))
#2 C:\xampp\htdocs\cimongo\system\CodeIgniter.php(320): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#3 C:\xampp\htdocs\cimongo\index.php(37): CodeIgniter\CodeIgniter->run()
#4 {main}
I am using this repo as a reference - https://github.com/bertugfahriozer/ci4mongodblibrary I have already placed the config and library files as in the repo and changed namespaces.
Upvotes: 0
Views: 1326
Reputation: 1781
have you tried below:
$puppyModel = model(puppyModel::class);
$result = $puppyModel->getList([your parameters here]);
Upvotes: 0
Reputation: 1
I just saw your question. I'm sorry for the late reply.
I think it will work if you edit your file like this:
<?php
namespace App\Models;
use ci4mongodblibrary\Libraries\Mongo;
class puppyModel{
i developing a cms/erp system with this repository. you can check from this link :
https://github.com/ci4-cms-erp
Upvotes: -1
Reputation: 11
use app\Models\puppyModel" not found
try this one
use App\Models\puppyModel
Upvotes: 1