1

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.

tereško
  • 56,151
  • 24
  • 92
  • 147

0 Answers0