【问题标题】:Error when try to use twig in slim, Fatal error: TwigView::getEnvironment()尝试在苗条中使用树枝时出错,致命错误:TwigView::getEnvironment()
【发布时间】:2012-05-19 15:29:33
【问题描述】:

当我想尝试使用 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();

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

【问题讨论】:

    标签: php php-5.3 twig slim


    【解决方案1】:

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

    从 git 下载 Twig 示例

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

    并在您的苗条 php 文件中,设置 twig 目录示例,如此代码

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

    【讨论】:

    • 最好:require_once '../vendor/autoload.php'; \Slim\Extras\Views\Twig::$twigDirectory = '../vendor/twig/lib/Twig'; \Slim\Extras\Views\Twig::$twigExtensions = array( 'Twig_Extensions_Slim', );
    • @Tim PHP Fatal error: Access to undeclared static property: Slim\\Views\\Twig::$twigDirectory
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 2018-08-29
    • 2020-06-05
    • 2019-08-02
    • 2013-06-15
    • 1970-01-01
    相关资源
    最近更新 更多