我刚刚更新了我的Silex应用程序的依赖项,现在我的一个模板突然失败并出现错误:
Twig_Error_Syntax: The function "render" does not exist.
在我执行composer update
之前,此工作正常。从作曲家输出中更新了以下内容:
- Removing symfony/options-resolver (v2.6.7)
- Installing symfony/options-resolver (v2.7.0)
Downloading: 100%
- Removing symfony/intl (v2.6.7)
- Installing symfony/intl (v2.7.0)
Downloading: 100%
- Removing symfony/form (v2.6.7)
- Installing symfony/form (v2.7.0)
Downloading: 100%
- Removing symfony/translation (v2.6.7)
- Installing symfony/translation (v2.7.0)
Downloading: 100%
- Removing symfony/validator (v2.6.7)
- Installing symfony/validator (v2.7.0)
Downloading: 100%
- Removing symfony/security (v2.6.7)
- Installing symfony/security (v2.7.0)
Downloading: 100%
- Removing symfony/finder (v2.6.7)
- Installing symfony/finder (v2.7.0)
Downloading: 100%
- Removing symfony/process (v2.6.7)
- Installing symfony/process (v2.7.0)
Downloading: 100%
- Removing symfony/twig-bridge (v2.6.7)
- Installing symfony/twig-bridge (v2.7.0)
Downloading: 100%
- Removing symfony/web-profiler-bundle (v2.6.7)
- Installing symfony/web-profiler-bundle (v2.7.0)
Downloading: 100%
- Removing symfony/stopwatch (v2.6.7)
- Installing symfony/stopwatch (v2.7.0)
Downloading: 100%
我的模板中使用的代码是:
{{ render (url('navigation')) | raw }}
我找不到任何暗示此功能已被弃用或已被替换的内容。我不确定哪个更新导致了这个问题,但我怀疑它是Twig-Bridge。我正在使用Twig版本1.18.1。
我对此问题有点困惑,这给我带来了一些问题,所以任何帮助都会很棒。
我承认我应该固定我正在使用的软件包的版本,这样我就可以用更有条理的方式测试升级。
谢谢,拉塞尔
更新1:
提供更多上下文的更新。
composer.json
"require": {
"silex/silex": "~1.2",
"silex/web-profiler": "1.0.*@dev",
"ruflin/elastica": "1.3.*@dev",
"dflydev/doctrine-orm-service-provider": "1.0.*@dev",
"monolog/monolog": "1.9.1",
"twig/twig": "1.18.*@dev",
"twig/extensions": "1.2.*@dev",
"symfony/yaml": "~2.4",
"symfony/console": "~2.4",
"symfony/twig-bridge": "~2.4",
"symfony/config": "~2.4",
"symfony/monolog-bridge": "~2.4",
"symfony/serializer": "~2.4",
"symfony/form": "~2.4",
"symfony/validator": "~2.4",
"symfony/translation": "~2.4",
"symfony/security": "~2.4",
"macedigital/silex-jms-serializer": "1.0.0",
"jdesrosiers/silex-jms-serializer-provider": "~0.1",
"mheap/silex-gravatar": "dev-master",
"mheap/gravatar-php": "dev-master",
"mheap/silex-assetic": "1.0.4",
"knplabs/knp-menu": "2.0.*@dev",
"predis/service-provider": "dev-master",
"pear/archive_tar": "dev-master",
"pear/pear_exception": "1.0.*@dev",
"wapmorgan/unified-archive": "dev-master",
"sybio/image-workshop": "dev-master",
"sybio/gif-frame-extractor": "dev-master",
"sybio/gif-creator": "dev-master",
"paypal/rest-api-sdk-php" : "*",
"kilte/silex-pagination": "1.1.*@dev",
"thispagecannotbefound/silex-markdown-parser": "dev-master",
"erusev/parsedown": "~1.4",
"erusev/parsedown-extra": "dev-master"
}
我使用以下命令注册Twig和UrlGenerator服务:
$app->register ( new \Silex\Provider\UrlGeneratorServiceProvider () );
$app -> register (new \Silex\Provider\TwigServiceProvider(), array(
'twig.options' => array("debug" => true)
));
$app['twig'] = $app -> share($app -> extend('twig', function($twig, $app) {
$twig -> addExtension(new \Twig_Extension_Debug());
return $twig;
}));
Twig本身仍在使用,任何没有“{{render}}”的模板都可以正常使用。
答案 0 :(得分:4)
我遇到了同样的问题。您是否在注册Web Profiler之前注册了HttpFragmentServiceProvider?这并不明显,但文档提到了它here。它对我很有用。
此致
答案 1 :(得分:0)
确保您拥有:
twig/twig
(也许您在执行编辑器更新之前删除了它)并通过composer安装了symfony/twig-bridge
。注册TwigServiceProvider()
和UrlGeneratorServiceProvider()
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => \__DIR__.'/path/to/templates/',
));
$app->register(new UrlGeneratorServiceProvider());