1. <small id='SpysA'></small><noframes id='SpysA'>

  2. <i id='SpysA'><tr id='SpysA'><dt id='SpysA'><q id='SpysA'><span id='SpysA'><b id='SpysA'><form id='SpysA'><ins id='SpysA'></ins><ul id='SpysA'></ul><sub id='SpysA'></sub></form><legend id='SpysA'></legend><bdo id='SpysA'><pre id='SpysA'><center id='SpysA'></center></pre></bdo></b><th id='SpysA'></th></span></q></dt></tr></i><div id='SpysA'><tfoot id='SpysA'></tfoot><dl id='SpysA'><fieldset id='SpysA'></fieldset></dl></div>

      <bdo id='SpysA'></bdo><ul id='SpysA'></ul>
      <tfoot id='SpysA'></tfoot>

      <legend id='SpysA'><style id='SpysA'><dir id='SpysA'><q id='SpysA'></q></dir></style></legend>

      Symfony/Doctrine:反序列化在行动与模板

      Symfony/Doctrine: Unserialize in action vs template(Symfony/Doctrine:反序列化在行动与模板)
    1. <legend id='95Dfl'><style id='95Dfl'><dir id='95Dfl'><q id='95Dfl'></q></dir></style></legend>

      <tfoot id='95Dfl'></tfoot>

      <small id='95Dfl'></small><noframes id='95Dfl'>

      • <bdo id='95Dfl'></bdo><ul id='95Dfl'></ul>

              <i id='95Dfl'><tr id='95Dfl'><dt id='95Dfl'><q id='95Dfl'><span id='95Dfl'><b id='95Dfl'><form id='95Dfl'><ins id='95Dfl'></ins><ul id='95Dfl'></ul><sub id='95Dfl'></sub></form><legend id='95Dfl'></legend><bdo id='95Dfl'><pre id='95Dfl'><center id='95Dfl'></center></pre></bdo></b><th id='95Dfl'></th></span></q></dt></tr></i><div id='95Dfl'><tfoot id='95Dfl'></tfoot><dl id='95Dfl'><fieldset id='95Dfl'></fieldset></dl></div>
                <tbody id='95Dfl'></tbody>

              1. 本文介绍了Symfony/Doctrine:反序列化在行动与模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                谁能告诉我为什么调用反序列化"在操作中可以正常工作,但在模板中会出现偏移错误?

                Can anyone tell me why calling "unserialize" works fine in an action but gives an offset error in a template?

                基本上可以将数据库文本结果反序列化为操作中的变量并将其传递给模板,在这种情况下它可以正常显示:

                It's basically possible to unserialize a database text result into a variable in an action and pass it to template, in which case it displays fine:

                $this->clean = unserialize($this->raw);
                <?php echo $clean ?>
                

                但如果直接在模板中调用则不会:

                But not if called directly in a template:

                <?php echo unserialize($raw) ?>
                

                想知道为什么会这样以及是否有一些解决方法.

                Would be interested in knowing why this is so and whether there's some workaround.

                谢谢.

                推荐答案

                Symfony 将所有模板变量放入一个 sfOutputEscaperArrayDecorator 类.所以当你编写 unserialize($var) 时,实际上是在尝试对 sfOutputEscaperArrayDecorator 类进行反序列化.

                Symfony puts all template variables into a sfOutputEscaperArrayDecorator class. So when you write unserialize($var), you are actually trying to unserialize the sfOutputEscaperArrayDecorator class.

                我建议在 settings.yml 中关闭输出转义:

                I recommend turning off output escaping in settings.yml:

                escaping_strategy:     false
                

                这是 Symfony 中一个愚蠢的、破坏性能的、不必要的功能,需要被扼杀.

                It is a stupid, performance-slaughtering, unnecessary feature of Symfony that needs murdered.

                更新:

                如果您关闭 escaping_strategy,您将需要使用 htmlSpecialCharacters() 手动转义用户的输入(以防止 XSS).

                If you turn off escaping_strategy, you will need to manually escape input from the users (to prevent XSS) with htmlSpecialCharacters().

                Symfony 类会为您做到这一点,但这意味着它还会转义每一个数字和字符——您已经知道其中 99% 是安全的(ID、日期、您自己的内容).当我关闭自动转义时,我的服务器负载明显下降.

                The Symfony class does that for you, but that means it also escapes every single number and character -- 99% of which you already know will be safe (IDs, dates, your own content). When I turned off the automatic escaping, my server load fell significantly.

                请记住,如果您将 sfOutputEscaperArrayDecorator 传递给部分,Symfony 双重应用这种自动转义,这意味着 > 将变为 <代码>&amp;gt;

                Keep in mind that Symfony double-applies this automatic escaping if you pass a sfOutputEscaperArrayDecorator to a partial, meaning > will become &amp;gt;

                这篇关于Symfony/Doctrine:反序列化在行动与模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Converting between timezones in PHP(在 PHP 中的时区之间转换)
                PHP - strtotime, specify timezone(PHP - strtotime,指定时区)
                Get current date, given a timezone in PHP?(获取当前日期,给定 PHP 中的时区?)
                List of US Time Zones for PHP to use?(PHP 使用的美国时区列表?)
                How to detect Ambiguous and Invalid DateTime in PHP?(如何在 PHP 中检测不明确和无效的 DateTime?)
                How to update timezonedb in PHP (updating timezones info)?(如何在 PHP 中更新 timezonedb(更新时区信息)?)

                  <tbody id='zjkOs'></tbody>

                  <tfoot id='zjkOs'></tfoot>
                • <legend id='zjkOs'><style id='zjkOs'><dir id='zjkOs'><q id='zjkOs'></q></dir></style></legend>
                  <i id='zjkOs'><tr id='zjkOs'><dt id='zjkOs'><q id='zjkOs'><span id='zjkOs'><b id='zjkOs'><form id='zjkOs'><ins id='zjkOs'></ins><ul id='zjkOs'></ul><sub id='zjkOs'></sub></form><legend id='zjkOs'></legend><bdo id='zjkOs'><pre id='zjkOs'><center id='zjkOs'></center></pre></bdo></b><th id='zjkOs'></th></span></q></dt></tr></i><div id='zjkOs'><tfoot id='zjkOs'></tfoot><dl id='zjkOs'><fieldset id='zjkOs'></fieldset></dl></div>

                    <small id='zjkOs'></small><noframes id='zjkOs'>

                      • <bdo id='zjkOs'></bdo><ul id='zjkOs'></ul>