我一直在尝试将Mongodb与CodeIgniter 4一起使用,但遇到了问题。
puppyModel.php-
<?php
namespace AppModels;
use CodeIgniterModel;
use AppLibrariesMongo;
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(控制器(-
<?php
namespace AppControllers;
use CodeIgniterController;
use appModelspuppyModel;
class Home extends BaseController{
public function index(){
$puppyModel = new puppyModel();
$data1 = $puppyModel->getList();
print_r($data1);
}
}
我收到这个错误-
CRITICAL - 2022-02-02 23:58:05 --> Class "appModelspuppyModel" not found
#0 C:xampphtdocscimongosystemCodeIgniter.php(825): AppControllersHome->index()
#1 C:xampphtdocscimongosystemCodeIgniter.php(412): CodeIgniterCodeIgniter->runController(Object(AppControllersHome))
#2 C:xampphtdocscimongosystemCodeIgniter.php(320): CodeIgniterCodeIgniter->handleRequest(NULL, Object(ConfigCache), false)
#3 C:xampphtdocscimongoindex.php(37): CodeIgniterCodeIgniter->run()
#4 {main}
我正在使用此回购作为参考-https://github.com/bertugfahriozer/ci4mongodblibrary我已经将配置文件和库文件放置在repo中,并更改了名称空间。
使用app\Models\puppyModel"未找到
试试这个
use AppModelspuppyModel
我刚刚看到你的问题。很抱歉回复迟了。
我认为如果你这样编辑你的文件,它会起作用:
<?php
namespace AppModels;
use ci4mongodblibraryLibrariesMongo;
class puppyModel{
我用这个存储库开发了一个cms/erp系统。你可以从这个链接查看:
https://github.com/ci4-cms-erp