【发布时间】:2022-06-22 02:24:53
【问题描述】:
我一直在尝试将 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}
我使用这个 repo 作为参考 - https://github.com/bertugfahriozer/ci4mongodblibrary 我已经将配置和库文件放在 repo 中并更改了命名空间。
【问题讨论】:
-
你的控制器中的
use app应该是use App- 看看能不能解决它。
标签: php mongodb codeigniter codeigniter-4