php - psr-4 autoload not working on namecheap.com live server
问题描述
I am using namecheap to host my website. I used psr-4 autoload and its working fine on my local computer but not on a live server. I have contatcted the customer support and followed all the instructions here https://www.namecheap.com/support/knowledgebase/article.aspx/9977/29/how-to-install-composer-on-shared-servers and the site is just showing a blank page. It appears my classes are not autoloading.
This is my composer.json file
{
"name": "webama/webama",
"type": "project",
"description": "The Webama Framework.",
"keywords": [
"framework",
"webama"
],
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
My application.php
namespace App\Framework;
class Application
{
protected $controller = DEFAULT_CONTROLLER;
protected $action = 'index';
protected $params = [];
public function __construct()
{
$this->parseURL();
if(file_exists(CONTROLLERS.$this->controller . '.php'))//'../app/controllers/'
{
$this->controller = 'App\controllers\\' . $this->controller;//App\controllers\
$this->controller = new $this->controller;
if(method_exists($this->controller, $this->action))
{
call_user_func_array([$this->controller, $this->action], $this->params);
}else{
echo "<h1>404 Not Found</h1>";
}
}
else{
echo "<h1>404 Not Found</h1>";
}
}
protected function parseURL()
{
$request = trim($_SERVER['REQUEST_URI'], '/');
if(!empty($request))
{
$url = explode('/', $request);
$this->controller = isset($url[0]) ? $url[0]. 'Controller' : DEFAULT_CONTROLLER;
$this->action = isset($url[1]) ? $url[1] : 'index';
unset($url[0], $url[1]);
$this->params = !empty($url) ? array_values($url) : [];
}
}
}
My index.php
require_once '../config/bootstrap.php';
use App\Framework\Application;
use App\Repositories\usersSessionRepository;
use App\Repositories\UserRepository;
new usersSessionRepository;
$user = new UserRepository();
$user->getRefIdFromUrl();
new Application;
My bootstrap.php
session_start();
require_once '../config/config.php';
require_once ROOT . 'app'.DS.'helpers'.DS.'helpers.php';
require_once __DIR__ . '/../vendor/autoload.php';
And my config files
// Site settings
define('BASE', 'https://orientFx.com');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__DIR__) . DS);
define('STORAGE', ROOT. 'storage' . DS);
define('CONTROLLERS', ROOT . 'app' . DS . 'controllers' . DS);
define('VIEWS', ROOT . 'app' . DS . 'views' . DS);
define('REPOSITORIES', ROOT . 'app' . DS . 'repositories' . DS);
define('DEFAULT_CONTROLLER', 'homeController');
// Site settings
define('DEFAULT_LAYOUT', 'default');
define('SITE_TITLE', 'Trade Fx');
// Debug settings
define('DEBUG', true);
// DB settings
define('DB_HOST', '127.0.0.1'); //Database host
define('DB_NAME', 'mvc'); //Database name
define('DB_USER', 'root'); //Database user
define('DB_PASSWORD', ''); //Database password
// Session settings
define('SESSION_NAME', 'user');
define('TOKEN_NAME', 'token');
// Session settings
define('COOKIE_NAME', 'hash');
define('COOKIE_EXPIRY', '604800');
Everything is working fine on localhost, but not on live server. I followed every instruction. Installed composer on my public folder, but nothing seems to work.
解决方案
推荐阅读
- java - 如何从 MySQL 数据库中获取数据并将其设置在 Java 中的 HashMap 中(注册/登录 GUI 程序)
- cmd - 以编程方式从命令行窗口复制所有文本
- flutter - 如何在我的 Flutter 中实现 Provider
- mysql - 如何从不同的虚拟机连接到 Docker MySQL 数据库
- c# - 在 ASP.NET 5 C# 中格式化货币
- bash - Linux cli pipe output of command into another command
- c# - 如何在 C# 中 POST 后更改页面
- php - 我想使用本地存储以符合 GDPR 的方式存储回访者
- c# - 双精度值设置为 +Infinity 或 NaN
- html - MVC 4 上的 HTML 表问题 - 使用 jQuery 动态删除行