问题
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