我正在尝试定义一个路由,以使用类Users中的方法。
在index.php中,我有这样的:
$app->post('/user', ''Users:getUsers');
在dependencies.php中,我有:
$container[''Users'] = function ($container) {
return new Users($container->get('ci'));
};
在我的课堂上,我有:
class Users {
protected $ci;
//Constructor
public function __construct(ContainerInterface $ci) {
$this->ci = $ci;
}
public function getUsers(){
$ci = $this->ci;
$settings = require __DIR__ . '/../../src/settings.php';
$user = $app = new 'Slim'App($settings);
$userList =$this->db->table('tbl_test')->get();
$output = array("data" => $userList);
return json_encode($output);
}
}
我得到的错误是找不到类"用户"
知道为什么吗?
您的用户类没有在项目中的任何地方定义。它可能来自您在dependencies.php 中的使用
看起来你没有使用自动加载。。。因此,请确保在执行中的某个位置包含一个包含类的语句。
您应该为类使用PSR-4命名空间。