2014-11-06 142 views
0

失蹤我下載中心鬍鬚(2.7)與作曲家的最後一個版本,Mustache_Autoloader與作曲家

"require": { 
     "mustache/mustache" : "2.7.*", 
     // etc... 
} 

但是當我嘗試:

use Mustache\Mustache_Autoloader; 

abstract class BaseController { 
    public function __construct() { 
     Mustache_Autoloader::register(); 
     /... 
    } 
    /... 
} 

error.log中說:

PHP Fatal error: Class 'Mustache\\Mustache_Autoloader' not found in 

雖然,Mustache_Autoloader沒有命名空間。

作曲家:composer/autoload_namespaces.php

return array(
     'Mustache' => array($vendorDir . '/mustache/mustache/src'), 
     //etc 
    ); 

而在我的主文件我不會忘記包括require 'vendor/autoload.php';但我不知道發生了什麼。任何想法?謝謝。

SOLUTION:

只有我需要在單詞的開頭加上 '\'。如new \Mustache_Engine()

現在,它的工作原理。感謝您的幫助:)

+0

試試這個「mustache/mustache」:「2.7.0」 – justrohu 2014-11-06 11:58:58

+0

它不起作用。 2.7。*這是當前版本,與2.7.0相同。 – Chemaclass 2014-11-06 12:02:49

回答

2

首先,您爲什麼要使用Mustache\Mustache_Autoloader? 作曲家應該照顧自動加載。

此外,我在https://github.com/bobthecow/mustache.php/blob/master/src/Mustache/Autoloader.php 中看到該類沒有名稱空間。
因此use Mustache\Mustache_Autoloader;失敗。

如果您想使用自動裝載機,您最好使用:
require '/path/to/mustache/src/Mustache/Autoloader.php'; Mustache_Autoloader::register();

+0

但是在composer/autoload_namespaces.php中有: 返回數組( 'Mustache'=> array($ vendorDir。'/ mustache/mustache/src'), //等 ); – Chemaclass 2014-11-06 12:14:53

+0

是的,所以你可以簡單地在你的代碼中使用'''$ m = new Mustache_Engine;'''。作曲家將自動加載課程。不需要鬍子/自動加載器,恕我直言。 – ivoba 2014-11-06 12:20:56

+0

但是,我需要在文件的頭部寫入:'使用Mustache \ Mustache_Engine;'並且我遇到同樣的問題... – Chemaclass 2014-11-06 12:23:02