我一直在尝试使用Mongodb与CodeIgniter 4,但面临的问题。
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(控制器)-
<?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);
}
}
我收到这个错误-
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}
我使用此存储库作为参考-https://github.com/bertugfahriozer/ci4mongodblibrary我已经将配置和库文件放置在存储库中并更改了名称空间。
2条答案
按热度按时间luaexgnf1#
找不到使用应用程序\模型\puppyModel”
试试这个
hgncfbus2#
我刚看到你的问题,很抱歉这么晚才回复。
我想如果你这样编辑你的文件,它会起作用:
我正在开发一个cms/erp系统。你可以从这个链接检查:
https://github.com/ci4-cms-erp