簡體   English   中英

未定義標識符“ twig”-Silex Framework

[英]Identifier “twig” is not defined - Silex Framework

感謝您的關注,

我已經創建了這個APP:

// web/index.php
require_once __DIR__.'/../vendor/autoload.php';

use Silex\Application;
use Silex\Provider\TwigServiceProvider;

$app = new Application();
$app['debug'] = true;

$app->register(new TwigServiceProvider(), array(
    'twig.path' => __DIR__.'/templates',
    'twig.class_path' => __DIR__.'/../vendor/twig/twig/lib',
    'twig.options' => array('cache' => __DIR__.'/../cache'),
));

$app->get('/', function () use ($app) {
    return $app['twig']->render('base.html.twig', array());
});

return $app;

但是,當我加載/在base.html.twig實例中加載時,出現此錯誤:

InvalidArgumentException: Identifier "twig" is not defined.
in /home/victor/workspace/testProject/vendor/pimple/pimple/lib/Pimple.php line 78
at Pimple->offsetGet('twig') in /home/victor/workspace/testProject/src/app.php line 41
at {closure}()
at call_user_func_array(object(Closure), array()) in /home/victor/workspace/testProject/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 145
at HttpKernel->handleRaw(object(Request), '1') in /home/victor/workspace/testProject/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 66
at HttpKernel->handle(object(Request), '1', true) in /home/victor/workspace/testProject/vendor/silex/silex/src/Silex/Application.php line 538
at Application->handle(object(Request)) in /home/victor/workspace/testProject/vendor/silex/silex/src/Silex/Application.php line 515
at Application->run() in /home/victor/workspace/testProject/web/index.php line 11

我遵循了官方教程,使用composer安裝了它,並仔細檢查了所有路徑...

嘗試刪除“ twig.class_path”條目。

我有這樣的東西,它的工作原理是:

    $options = [
        'twig.path' => ...,
        'twig.options' => [
            'strict_variables'  => false
        ]
    ];

    $this->_app->register(new TwigServiceProvider(), $options);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM