我正在将 Kohana 中的网站逐渐移植到 Symfony 2。现在我正在 Symfony2 中编写后端命令,例如 cron 来发送电子邮件通知。
如何访问 twig 中的基本 url。我可以做一些配置,以便从控制台和 http 请求访问 twig 中的 url 相同吗?
我已经提到过这一点,
http://symfony.com/doc/current/cookbook/console/sending_emails.html
http://symfony.com/doc/current/cookbook/templated/global_variables.html
这里给出了如何配置它,但没有提到如何访问它,我假设我必须使用 {{ router.request_context.host }} 。
但我的问题是,是否有任何方法可以在 console 和 HTTP 之间保持一致?
例如 {{ url }} ?
这对我有用。
在config.yml中:
twig:
globals:
base_url: "http://www.example.com/"
Run Code Online (Sandbox Code Playgroud)
在树枝模板中:
{{ base_url }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17600 次 |
| 最近记录: |