【发布时间】:2014-03-19 13:51:27
【问题描述】:
我是作曲家和自动加载器的新手。我想我也缺乏文件组织策略。 我正在尝试在 slimframework 上建立一个新项目。 我有一些 Slim 课程。但我无法在我的项目中自动加载它们。
/
- composer.json
- composer.phar
- 供应商
- 配置
- someapiparams.php
- 数据库.php
- cache.php
- general.php
- 公开
- index.php
- 型号
- 库
- 富
- 修身
- Config.php
- Cache.php
/composer.json:
"autoload": {
"psr-0": {
"Foo": "libraries/"
}
}
/libraries/Foo/Slim/Config.php:
<?php
class Config {
/**
* Loads a file based on $key param under ROOT . "/config",
* if not already loaded.
* Then returns an array.
*/
public static function get($key) {}
}
/libraries/Foo/Slim/Cache.php:
<?php
class Cache{
/**
* Initialize a caching engine defined in config file if not already done.
* Then runs corrensponding engine methods for getting and setting.
*/
public static function init() {
$config = Config::get("cache");
// initialize driver.
}
public static function __get($key) {}
public static function __set($key, $value, $params) {}
}
/public/index.php:
require ROOT."/vendor/autoload.php";
$app = new Slim\Slim();
var_dump(Config::get("database")); exit;
//var_dump(Foo\Slim\Config::get("database")); exit;
//var_dump(Slim\Config::get("database")); exit;
错误是找不到配置类。
【问题讨论】:
标签: composer-php autoload slim