2016-05-18 17 views
0

我剛剛完成通過Xampp在本地構建網站。一切正常,它使用PHP 5.6版本。我使用作曲家來使用一些第三方應用程序,如Guzzle和Stringy。完成後,我上傳到我的Godaddy webhosting帳戶,該帳戶使用PHP 5.5。當我加載網站我得到這個錯誤:PHP自定義命名空間不工作

致命錯誤:類「利布斯\型號\ Site_Settings」不是的public_html /門/ conf目錄/ settings.php中發現了線81

但是廠商的命名空間只是工作精細。我沒有得到任何錯誤。赫克我沒有得到任何錯誤與我的自定義類。我正在使用作曲家自動載入所有內容。一切都在本地完美運行,任何使用自定義命名空間的類都不能只在我的虛擬主機帳戶上運行。在我的課我都在上面:

namespace Libs\Model; 

我還用括號

namespace Libs\Model {\\code here} 

試圖研究這個問題,想出什麼嘗試。有什麼建議麼?在psr4自動加載文件中顯示:

'Libs\\' => array($baseDir . '/lib') 

我驗證了$ baseDir指向正確的文件夾。

UPDATE

這裏是從類進出口試圖調用代碼。很簡單:

namespace Libs\Model; 

class Site_Settings { 

    private $dbconn; 

    public function __construct($dbconn) 
    { 

     $this->dbconn = $dbconn;    

    } 

    public function findSiteSettings($domain) 
    { 

     //We clean any variables being passed to the query 
     $domain = $this->dbconn->escape($domain); 

     //We turn on query caching 
     $this->dbconn->cache_queries = TRUE; 

     //This is the query statement to run 
     $query = $this->dbconn->get_row(" 
       SELECT 
        jp.*, 
        js.stateabb, 
        js.statename, 
        js.statecountry 
       FROM 
        job_site AS jp 
       INNER JOIN 
        job_state AS js 
       ON 
        jp.stateid = js.id 
       WHERE 
        jp.sitedomain = '$domain' 
       AND 
        jp.active = 1 
       LIMIT 
        1 
       "); 

     //We turn off query caching 
     $this->dbconn->cache_queries = FALSE; 

     //We now return any rows found 
     return $query; 

    } 

} 

這是林如何調用它:

//We include the autoloader that is needed to load all vendors for this site 
    include(VENDORS .'autoload.php'); 

    //We get the site settings for this job site 
    $settings = new Libs\Model\Site_Settings($global_db); 
    $site_settings = $settings->findSiteSettings($global_sitedomain); 

這是作曲家PSR4我的自動加載文件:

$vendorDir = dirname(dirname(__FILE__)); 
$baseDir = dirname(dirname($vendorDir)); 

return array(
    'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 
    'Stringy\\' => array($vendorDir . '/danielstjules/stringy/src'), 
    'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'), 
    'Libs\\' => array($baseDir . '/lib'), 
    'League\\Plates\\' => array($vendorDir . '/league/plates/src'), 
    'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'), 
    'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'), 
    'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'), 
    'Cocur\\Slugify\\' => array($vendorDir . '/cocur/slugify/src'), 
); 

更新#2 這裏是我的作曲文件

"autoload": { 
     "classmap": [ 
      "lib/vendor/ezsql/mysqli/ez_sql_mysqli.php", 
      "lib/vendor/ezsql/shared/ez_sql_core.php", 
      "lib/helper/url.php", 
      "lib/helper/html.php", 
      "lib/helper/form_message.php", 
      "lib/helper/email_generator.php", 
      "lib/helper/pagination.php" 
     ], 
     "psr-4": {"Libs\\": "lib"} 
    }, 
    "require": { 
     "league/plates": "^3.1", 
     "guzzlehttp/guzzle": "^6.2", 
     "phpmailer/phpmailer": "^5.2", 
     "cocur/slugify": "^2.1", 
     "danielstjules/stringy": "^2.3", 
     "wixel/gump": "^1.3", 
     "jwage/purl": "^0.0.7" 
    } 
} 

回答

0

您尚未提供足夠的信息來真實回答你的問題。 php文件位於Libs \ Model \ Site_Settings的位置在哪裏?您是否正在處理像OSX這樣的區分大小寫的系統,並將其上傳到Linux等區分大小寫的系統?你使用的是什麼自動加載標準?看起來您正在使用PSR-0和PSR-4。

您可能需要一個自動加載路徑添加到您的composer.json:

"autoload": { 
     "psr-4": { 
      "Libs\\Model\\": "lib/src/model", 
+0

我剛添加的代碼。這有幫助嗎? – John

+0

Site_Settings.php和./vendor/ –

+1

在哪裏從主目錄:\ lib \ vendor \ model \ site_settings.php哦,man是一個區分大小寫的問題嗎?廢話,如果這是我即時愚蠢作爲地獄 – John