![](/img/trans.png)
[英]Fatal error: Uncaught Error: Class 'maimana\App' not found — slim3
[英]Fatal error: Uncaught Error: Class 'App\Config' not found
我已經構建了一個自定義 MVC 框架。 本地工作正常,當我嘗試讓它在實時共享托管服務器上工作時,我會收到此錯誤:
瀏覽器中的錯誤消息:
致命錯誤:未捕獲的錯誤:在 /www/htdocs/user/project/public/index.php:19 中找不到類 'App\Config' 堆棧跟蹤:在 /www/htdocs/user/project/ 中拋出 #0 {main}第 19 行的 public/index.php
Composer.json 文件:
{
"require": {
"filp/whoops": "^2.3",
"phpmailer/phpmailer": "^6.0"
},
"autoload": {
"psr-4": {
"Core\\": "core/",
"App\\": "app/"
}
}
}
我的文件夾和文件結構:(整個項目在文件夾內:“項目”)
索引.php 文件
<?php
/**
* Front controller
*/
use App\Config;
/**
* Composer autoloading
*/
require dirname(__DIR__) . '/vendor/autoload.php';
/**
* Whoops Error and Exception handling
*/
if (Config::SHOW_ERRORS == true){
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
}
/**
* Sessions
*/
session_start();
/**
* Routing
*/
$router = new Core\Router();
// Add the routes
$router->add('', ['controller' => 'Home', 'action' => 'index']);
配置.php 文件:
<?php
/**
* Application configuration
*/
namespace App;
class Config {
/**
* Database host
* @var string
*/
const DB_HOST = 'localhost';
/**
* Mail SMTP Port
* @var int
*/
const SMTP_PORT = '2525';
}
我部署到服務器的方法:
composer install
(我也試過: composer install --no-dev
)我現在已經重復了這個過程幾次,但它仍然無法正常工作
就我而言,問題是由在 Windows 中使用符號鏈接引起的。 我正在使用 WAMP 和 PHP 框架 CodeIgniter(版本 4.2.1)。 某些版本的 CodeIgniter 有這個問題。
可能的原因:
我認為原因是使用了 PHP 函數 file_exists。 在某些情況下,當路徑包含帶有某些字符的符號鏈接時,該函數會返回 FALSE。 或者問題在於清理文件名。
可能的解決方案:
解決方案 5 對我來說是最簡單的。 我必須刪除符號鏈接名稱中的方括號 (),這解決了問題。
也許這對其他人有幫助。
我剛剛嘗試做同樣的事情,它似乎工作,檢查這個:
/index.php
<?php
require dirname(__DIR__) . '/vendor/autoload.php'; // It must be called first
use App\Config;
echo Config::get('test');
// Result: test
/App/Config.php
namespace App;
class Config
{
public function get($str)
{
return $str;
}
}
這是區分大小寫的問題 - 您的自動加載規則使用app
作為目錄名稱,但這實際上是App
。 這可能適用於不區分大小寫的文件系統 (Windows),但不適用於區分大小寫的文件系統 (Linux)。 您應該將自動加載規則修復為:
{
"require": {
"filp/whoops": "^2.3",
"phpmailer/phpmailer": "^6.0"
},
"autoload": {
"psr-4": {
"Core\\": "Core/",
"App\\": "App/"
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.