简体   繁体   English

未定义标识符“ twig”-Silex Framework

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

Thanks for you interest, 感谢您的关注,

I have create this APP: 我已经创建了这个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;

But, when I load / in instance of base.html.twig be loaded, this error appear: 但是,当我加载/在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

I have followed the official tutorial, installed it using composer and double checked all the paths... 我遵循了官方教程,使用composer安装了它,并仔细检查了所有路径...

Try removing the "twig.class_path" entry. 尝试删除“ twig.class_path”条目。

I have it like this, and it works: 我有这样的东西,它的工作原理是:

    $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