通过 Twig/Timber 传递 PHP 全局变量 [英] Passing PHP global variables via Twig/Timber

查看:36
本文介绍了通过 Twig/Timber 传递 PHP 全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据https://stackoverflow.com/a/19554524/6450661,标准Twig提供了一种通过{{ app.request }} 我可以用它来传递 $_GET、$_POST、$_SESSION 等变量.

According to https://stackoverflow.com/a/19554524/6450661, standard Twig provides a method via {{ app.request }} that I can use to pass $_GET, $_POST, $_SESSION, etc. variables.

使用Timber,有没有类似的方法?我可以使用 Timber\URLHelper 的 get_params() 方法来访问 $_GET 变量,但这就是我能找到的全部.

Using Timber, is there a similar method? I can use Timber\URLHelper's get_params() method to access $_GET variables, but that's about all I can seem to find.

推荐答案

我查看了源代码,至少找到了 $_GET 和 $_POST 变量的答案,所以如果它对任何人有帮助,就在这里.

I looked through the source code and at least found the answer for $_GET and $_POST variables, so here it is if it helps anyone.

要访问 $_POST 变量,请使用:

To access $_POST variables, use this:

{{ request.post.name_of_var }}

要访问 $_GET 变量,请使用:

To access $_GET variables, use this:

{{ request.get.name_of_var }}

这篇关于通过 Twig/Timber 传递 PHP 全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆