php - 一类得到“PHP 致命错误:未捕获的错误:类...”,但其他类没有
问题描述
我收到此错误,不知道为什么。
致命错误:未捕获的错误:在 /Applications/MAMP/htdocs/lpad.com/config/auth.php:8 中找不到类“DBC”堆栈跟踪:#0 /Applications/MAMP/htdocs/lpad.com/config/actions .php(3): Auth->__construct() #1 {main} 在第 8 行的 /Applications/MAMP/htdocs/lpad.com/config/auth.php 中抛出
调用此类的所有其他公共函数都可以正常工作。DBC 是我的数据库连接类。所有页面都是config.php文件中的require_once
授权文件
class Auth
{
private $db;
public function __construct()
{
$this->db = new DBC;
}
// Login in Lead
public function login($ld_id)
{
$this->db->query('SELECT ld_id FROM leads WHERE ld_id = :ld_id');
$this->db->bind('ld_id', $ld_id, '');
$result = $this->db->fetchSingle();
return $result;
}
// Get Admin Sidebar Links
public function getCats($ld_lp_access)
{
$this->db->query('SELECT * FROM categories WHERE cat_access => :ld_lp_access');
$this->db->bind('ld_lp_access', $ld_lp_access, 'int');
$result = $this->db->fetchMultiple();
return $result;
}
}
动作.php
require_once 'auth.php';
$auth = new Auth();
if (isset($_POST['action']) && $_POST['action'] == 'display_cats') {
$output = '';
$cats = $auth->getCats($ld_lp_access);
if ($cats) {
$output = '<ul>';
foreach ($cats as $row) {
$output .= '<li class="side-item"><a href="' . $row['cat_link'] . ' class="side_link"><i class="' . $row['cat_fa'] . ' fa-lg mr-1"></i>' . $row['cat_name'] . '</a></li>';
}
$output .= '</ul>';
} else {
echo 'No Categories Listed';
}
ajax.js
$(document).ready(function() {
displayCats();
function displayCats() {
$.ajax({
url: '../config/actions.php',
method: 'POST',
data: {
action: 'display_cats'
},
success: function(response) {
$("#showCats").html(response);
}
})
}
});
解决方案
显然,auth.php
似乎不知道您的 DBC 类 - 您需要像在actions.php
.
推荐阅读
- java - Spring-WS:消费服务
- ssh - 谷歌云平台:SSH 到谷歌云实例将有“权限被拒绝(公钥)”
- javascript - 移动设备上的范围输入滑块
- laravel - 使用 mongodb 时如何对 API 进行 Laravel 身份验证?
- reactjs - 将反应可拖动移动到屏幕一侧?
- svg - 如何在 Vuetify 中添加自定义 SVG 图标 - Vue
- java - Spark 作业完成,写入输出文件但执行程序状态为 KILLED?
- python - 尝试使用 python 读取 oracle 数据库时出错
- php - 即将存储与父复选框相关的子复选框的多个值,数据只存储一次
- c++ - 在具有成员函数的运行线程期间破坏的对象