Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Twig Silex中的小枝延伸_Twig_Silex - Fatal编程技术网

Twig Silex中的小枝延伸

Twig Silex中的小枝延伸,twig,silex,Twig,Silex,我尝试将细枝扩展加载到Silex中,但得到: 找不到“细枝扩展\u扩展\u文本” 我首先在自动加载器中注册细枝扩展: $app['autoloader']->registerPrefixes(array( 'Twig_' => array(__DIR__.'/../vendor/Twig-extensions/fabpot/lib'))); 然后注册小枝: $app->register(new Silex\Provider\TwigServiceProvider(), ar

我尝试将细枝扩展加载到Silex中,但得到:

找不到“细枝扩展\u扩展\u文本”

我首先在自动加载器中注册细枝扩展:

$app['autoloader']->registerPrefixes(array( 'Twig_'  => array(__DIR__.'/../vendor/Twig-extensions/fabpot/lib')));
然后注册小枝:

$app->register(new Silex\Provider\TwigServiceProvider(), array(
        'twig.path' => __DIR__ . '/../views',
         'twig.class_path' => __DIR__ . '/../vendor/twig/lib',
));
并添加扩展名

$oldTwigConfiguration = isset($app['twig.configure']) ? $app['twig.configure']: function(){};
$app['twig.configure'] = $app->protect(function($twig) use ($oldTwigConfiguration) {
    $oldTwigConfiguration($twig);
    $twig->addExtension(new Twig_Extensions_Extension_Text());
});
Pathes似乎是正确的,而Twig本身工作正常


有什么想法吗?原因很简单。PEAR约定自动加载映射定义为“前缀”=>“路径”。您正在为细枝扩展设置“细枝”前缀,然后注册细枝服务提供商,该提供商将覆盖它,指向细枝本身

解决方法是使用“Twig_u2;”以外的前缀,最好是更具体的前缀。类似于“小树枝”


这应该可以解决问题。

在Silex 1.3中,您可以使用新的
extend
痘痘治疗方法:

$app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
    $twig->addExtension(new \My\Twig\Extension\SomeExtension($app));
    return $twig;
}));
在Silex 2.0中,首先:

然后使用

通过扩展
Twig
服务,您可以在使用Twig之前配置Twig环境

以及:


它在Twig处不使用下划线:$app['autoloader']->registerPrefixes(数组('Twig'=>array(DIR./../vendor/Twig extensions/fabbot/lib));
$app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
    $twig->addExtension(new \My\Twig\Extension\SomeExtension($app));
    return $twig;
}));
$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__.'/views',
));
$app->extend('twig', function($twig, $app) {
    $twig->addExtension(new Twig_Extensions_Extension_Text());
    return $twig;
});