【发布时间】:2015-01-23 01:35:33
【问题描述】:
app/Core
contollers
这是我放置主类的网站结构,我使用 composer psr-4 规则在app/Core 文件夹下导入类。
composer.json
{
"autoload": {
"psr-4": {
"Core\\": ["app/Core"]
}
}
}
index.php
<?php
include 'vendor/autoload.php';
new Core/Api; // it's work
它工作正常,但我想在控制器文件夹下自动加载类不使用使用namespace,所以我使用__autoload函数,如:
index.php
<?php
include 'vendor/autoload.php';
function __autoload($class_name) {
include 'controllers/' . $class_name . '.php';
}
new Test // Fatal error: Class 'test'
如果我删除include 'vendor/autoload.php'; 它将起作用,所以我认为代码是正确的,我知道我可以在composer.json 中使用classmap,但是每次添加新类时都需要dump-autoload,如何处理冲突?
【问题讨论】:
标签: php composer-php