我正在学习Composer的工作方式(对dev ^^来说是新的),但我正在努力解决自动加载问题...
这是我的composer.json:
"autoload": {
"psr-4": {
"OCFram\\": "/../lib/",
"App\\": "/../",
"Model\\": "/../lib/vendors/",
"Entity\\": "/../lib/vendors/",
"FormBuilder\\": "/../lib/vendors/",
"Slug\\": "/../lib/vendors/"
}
},
例如:
致命错误:未捕获的错误:类'App \ Frontend \ FrontendApplication' 找不到
FrontendApplication路径(来自composer.json):**
../ App / Frontend / FrontendApplication.php
这里是带有命名空间的FrontendApplication.php:
<?php
namespace App\Frontend;
use \OCFram\Application;
class FrontendApplication extends Application
{
public function __construct()
{
parent::__construct();
$this->name = 'Frontend';
}
public function run()
{
$controller = $this->getController();
$controller->execute();
$this->httpResponse->setPage($controller->page());
$this->httpResponse->send();
}
}
另外,我注意到供应商/撰写者上的此文件(autoload_psr4.php):
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Slug\\' => array('/lib/vendors'),
'OCFram\\' => array('/lib'),
'Model\\' => array('/lib/vendors'),
'FormBuilder\\' => array('/lib/vendors'),
'Entity\\' => array('/lib/vendors'),
'App\\' => array('/'),
);
不胜感激:)
[编辑]
所以我改变了从 “ App \”:“ /../”(没有意义) 至 : “ App \”:“ ../",
现在在另一个作曲家转储自动加载后,我得到了这个:
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Slug\\' => array($baseDir . '/../lib/vendors'),
'OCFram\\' => array($baseDir . '/../lib'),
'Model\\' => array($baseDir . '/../lib/vendors'),
'FormBuilder\\' => array($baseDir . '/../lib/vendors'),
'Entity\\' => array($baseDir . '/../lib/vendors'),
'App\\' => array($baseDir . '/..'),
);
但是当我尝试php index.php时仍然遇到相同的问题: 致命错误:未捕获错误:类 找不到“ App \ Frontend \ FrontendApplication”
答案 0 :(得分:0)
截至您的声明:
FrontendApplication路径(来自composer.json):**
../ App / Frontend / FrontendApplication.php
您的文件夹结构似乎是:
/App
/<some-dir>/composer.json
似乎您只是在路径中错过了App
,所以不需要前导或尾部的斜杠。
"autoload": {
"psr-4": {
"OCFram\\": "../lib",
"App\\": "../App",
"Model\\": "../lib/vendors",
"Entity\\": "../lib/vendors",
"FormBuilder\\": "../lib/vendors",
"Slug\\": "../lib/vendors"
}
},