Mustache_Autoloader missing with Composer

Deadly 提交于 2019-12-13 05:17:00

问题


I dowload the last versión of Mustache (2.7) with Composer,

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

but when I try:

use Mustache\Mustache_Autoloader;

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

the error.log said:

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

Although, Mustache_Autoloader hasn't namespaces.

Composer has: composer/autoload_namespaces.php:

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

And in my main file I don't forget include require 'vendor/autoload.php'; But I don't know what happend. Any idea? Thanks.

SOLUTION:

Only I need to add '\' at the beginning of the word. like new \Mustache_Engine().

Now it works. Thanks for your help :)


回答1:


First, why do you want to use the Mustache\Mustache_Autoloader ? composer should take care of the autoloading.

Further i see in https://github.com/bobthecow/mustache.php/blob/master/src/Mustache/Autoloader.php that this class has no namespace.
Therefor use Mustache\Mustache_Autoloader; fails.

If you want to use the autoloader you better use:
require '/path/to/mustache/src/Mustache/Autoloader.php'; Mustache_Autoloader::register();.



来源:https://stackoverflow.com/questions/26778877/mustache-autoloader-missing-with-composer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!