2014-01-12 38 views
1

我正在使用作曲家自動加載爲我構建的mvc框架。我已經測試過它,並在Vagrant環境(配置:http://pastebin.com/aAs2TFMh)甚至在Windows上工作。作曲家自動加載不起作用

我得到這個錯誤:{"error":{"type":"Whoops\\Exception\\ErrorException","message":"Class 'Elysium\\Controllers\\Error' not found","file":"\/home\/glendme\/public_html\/clubsmade\/src\/elysium\/core\/Router.php","line":99}}

然而,當我與Ubuntu 13.04 + php5.4部署它在我的VPS就開始給類未找到錯誤。當我將它放在共享主機上時也是如此。

我試過自我更新,刪除供應商目錄和作曲家安裝再次無濟於事。

這裏是我的composer.json,

{ 
"name": "glend/elysium", 
"description": "PHP MVC Framework.", 
"version" : "0.1.0-dev", 
"keywords" : ["mvc", "framework", "elysium", "glend"], 
"homepage" : "http://mvc.blueberry.al", 
"license" : "GPL-3.0+", 
"authors": [ 
    { 
     "name": "Glend Gjermeni", 
     "email": "[email protected]", 
     "homepage": "http://glend.me", 
     "role": "Developer" 
    } 
], 
"support": { 
    "email": "[email protected]" 
}, 
"autoload": { 
    "psr-0": {"Elysium": "src/"} 
}, 
"require": { 
    "filp/whoops": "1.*", 
    "swiftmailer/swiftmailer": "*", 
    "vlucas/valitron": "1.1.5", 
    "ircmaxell/password-compat": "1.0.3" 
} 

}

而且Router.php:

<?php 

namespace Elysium\Core; 
use Elysium\Controllers; 

/** 
* Manages all routing and URL requests for the framework. 
* @package Elysium\Core 
*/ 
class Router 
{ 
    private $url, $controller, $method, $params; 
    private $allowedChars = array('-', '_', '/', '\\', '.'); 

    /** 
    * Reads the passed URL from GET request into controller, method and params variables. 
    */ 
    public function __construct() 
    { 
     if(!empty($_GET['page'])) 
     { 
      if(ctype_alnum(str_replace($this->allowedChars, '', $_GET['page']))) 
      { 
       $this->url = $_GET['page']; 
      } 
      else 
      { 
       throw new Exception("Malformed URL"); 
      } 
     } 
     else 
     { 
      $this->url = 'index'; 
     } 

     $this->url = explode('/', $this->url); 

     $this->controller = implode('_', array_map('ucfirst', explode('_', str_replace('-', '_', array_shift($this->url))))); 
     $this->method = explode('_', str_replace('-', '_', array_shift($this->url))); 

     for($i = 1; $i < count($this->method); $i++) 
     { 
      ucfirst($this->method[$i]); 
     } 

     $this->method = implode('_', $this->method); 
     $this->params = &$this->url; 
    } 

    /** 
    * Initializes correct controller based on URL requested. 
    */ 
    public function commit() 
    { 
     $class = "Elysium\\Controllers\\$this->controller"; 

     if(class_exists($class)) 
     { 
      if(method_exists($class, $this->method)) 
      { 
       if(empty($this->params)) 
       { 

        $ctrl = new $class; 
        $ctrl->{$this->method}(); 
       } 
       else 
       { 
        $ctrl = new $class; 
        $ctrl->{$this->method}($this->params); 
       } 
      } 
      else if(empty($this->method)) 
      { 
       $ctrl = new $class; 
       $ctrl->index(); 
      } 
      else 
      { 
       self::error(404); 
      } 
     } 
     else 
     { 
      self::error(404); 
     } 
    } 

    /** 
    * Initializes default Error controller based on error code provided and shows the appropriate error page. 
    * @param $code 
    */ 
    public static function error($code) 
    { 
     switch($code) 
     { 
      case 404: 
      { 
       $ctrl = new Controllers\Error(); 
       $ctrl->notFound(); 
       break; 
      } 
      default: 
      { 
       break; 
      } 
     } 
    } 
} 
+0

您的信息中沒有任何內容可以解釋您所遇到的情況。請明確點。列出確切的錯誤消息,列出它所在的代碼行,並列出應該丟失的類以及它所在的位置。 – Sven

+0

@Sven我很抱歉沒有包括這個錯誤,但是你不會從代碼中獲得太多東西,它只是一個被灌輸的類。我現在添加了它們,並且所有類不僅缺少一個類,它不自動加載任何內容。 –

+1

您可能在名稱空間的字母大小寫不匹配。命名空間用作路徑的一部分--Windows不關心大小寫,Linux是特定於案例的。 – Danack

回答

5

固定它自己的文件夾名稱必須大寫字母就像命名空間,如果你堅持使用PSR-0。如果你不想改變,你可以使用作曲家的班級地圖。

+0

這就是我所懷疑的,但在你的問題中沒有證據。 – Sven