【发布时间】:2015-02-19 04:55:57
【问题描述】:
大家好,我正在制作 mvc 框架并想使用通过 composer 安装的 Twig 模板系统。我用这个教程 MVC 这是我的 composer.json 文件
{
"require": {
"twig/twig": "~1.0"
},
"autoload":{
"files":[
"config/config.php"
]
}
}
当我将require_once ROOT.'\vendor\autoload.php' 添加到 index.php 或 bootstrap.php 时出现错误:
- 可能缺少包含类“ItemsController”的文件“items.php”。 2. 'items.php'中缺少方法'index'
但是当我像这样在 library/View.php 中添加 require_once 时:
class View {
public $loader;
public $twig;
public $arg;
public function __construct() {
require_once (ROOT.'/vendor/autoload.php');
$loader = new Twig_Loader_Filesystem(ROOT.'/application/views');
$this->twig = new Twig_Environment($loader);
}
}
当我在 View 类之外添加自动加载时,问题出在哪里?所有建议都会有所帮助,谢谢。
【问题讨论】:
-
那个教程与MVC无关
-
你能给我一个更好的例子吗?
标签: php twig composer-php