gpt4 book ai didi

php - 尝试在 slim 中使用 twig 时出错, fatal error :TwigView::getEnvironment()

转载 作者:搜寻专家 更新时间:2023-10-31 21:15:09 25 4
gpt4 key购买 nike

当我想尝试使用 Twig View 实现 slim 时遇到问题。
错误:

Fatal error: TwigView::getEnvironment() [function.require]: Failed opening required '/Autoloader.php' (include_path='.:/opt/local/etc/php5') in /opt/local/apache2/htdocs/slim/Slim-Extras/Views/TwigView.php on line 87

这是我的代码

require '/opt/local/apache2/htdocs/slim/Slim/Slim.php';
17 require '/opt/local/apache2/htdocs/slim/Slim-Extras/Views/TwigView.php';
18 /*
19 * initialize slim to use TwigView Handler
20 */
21 $app = new Slim(array(
22 'view'=> new TwigView()
23 ));
24 //$app->init(array('view' => 'TwigView'));
25 $app->get('/',function() use ($app){
26 $title = "hi there are new twig";
27 $body = "and this is body maybe you are have idea for this content...:)";
28 $data = array('title' => $title, 'body' => $body);
29 $app->view()->setData(array('title' => $title, 'body' => $body));
30 $app->render('TopPage.html');
31 // echo "hai you are coll man";
32
33 });
34 $app->get('/hello/',function(){
35 echo 'Hello' ;
36 });
37 $app->get('/hello/:name',function($name){
38 echo "yaay...exellent ".$name;
39 });
40 $app->run();

有什么建议吗?我不知道为什么会出现这样的错误。

最佳答案

对不起,我自己解决了我的问题,我找到了解决方案。

从 git 下载 Twig 示例

git clone git://github.com/fabpot/Twig.git

并且在你的 slim php 文件中,像这样的代码设置 twig 目录示例

TwigView::$twigDirectory = '/opt/local/apache2/htdocs/slim/Twig/lib/Twig';
TwigView::$twigExtensions = array(
'Twig_Extensions_Slim'
);

关于php - 尝试在 slim 中使用 twig 时出错, fatal error :TwigView::getEnvironment(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10544503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com