首页 > 解决方案 > 一类得到“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);
      }
    })
  }
});

标签: phpclassfatal-error

解决方案


显然,auth.php似乎不知道您的 DBC 类 - 您需要像在actions.php.


推荐阅读