Composer不会自动加载类。
我的作曲家档案:
{
"autoload": {
"psr-4": {
"core\\" : "/src/core/",
"Rec\\RecipBundle\\Entity\\" : "/src/Rec/RecipBundle/Entity/",
"Rec\\RecipBundle\\Controller\\" : "/src/Rec/RecipBundle/Controller/"
},
"classmap": [
"src/core/App.php",
"src/core/View.php",
"src/core/Controller.php"
]
}
}
生成的类图是错误的。例如, C:\ Bitnami \ wampstack-5.6.20-0 \的Apache2 \ htdocs中\ WWW \ Plan2own \厂商\作曲家\ autoload_psr4.php
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'core\\' => array('/src/core'),
'Rec\\RecipBundle\\Entity\\' => array('/src/Rec/RecipBundle/Entity'),
'Rec\\RecipBundle\\Controller\\' => array('/src/Rec/RecipBundle/Controller'), );
如果我尝试加载类Home,我将得到该文件不存在的错误,尽管它存在。例如在 C:\ Bitnami \ wampstack-5.6.20-0 \的Apache2 \ htdocs中\ WWW \ Plan2own \ SRC \芯\ App.php
namespace src\core;
use Rec\RecipBundle\Controller\Home;
class App{
public function __construct(){
$home = new Home(); //gives error
} }
为了工作,我必须手动更正autoload_psr4.php。如何自动生成?更正后的工作版本的baseDir前置于C:\ Bitnami \ wampstack-5.6.20-0 \ apache2 \ htdocs \ www \ Plan2own \ vendor \ composer \ autoload_psr4.php:
return array(
'core\\' => array($baseDir . '/src/core'),
'Rec\\RecipBundle\\Entity\\' => array($baseDir .'/src/Rec/RecipBundle/Entity'),
'Rec\\RecipBundle\\Controller\\' => array($baseDir .'/src/Rec/RecipBundle/Controller'), );