如何在Symfony 1.2的表单字段中允许某些HTML标签 [英] How to allow certain HTML tags in a form field in Symfony 1.2

查看:78
本文介绍了如何在Symfony 1.2的表单字段中允许某些HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Symfony玩耍,遇到了路障.

I'm playing around with Symfony and have encountered a road block.

我创建了一个模型"CmsPage",其中包含一个名为"content"的字段,该字段存储为Clob(我相信这是特定于学说的).当我创建应用程序时,我设置为"--escaping-strategy = on",以便在编辑CmsPage时输入任何HTML,该CmsPage用html实体或沿这些行进行编码.我想允许这个领域的html和快速谷歌搜索并没有太大帮助.也许我在搜索错误的字词.

I created a model "CmsPage" which has a field called "content" which is stored as a clob (this is specific to doctrine I believe). When I created the app I set "--escaping-strategy=on" so if I enter any html when editing a CmsPage that gets encoded with html entities or something along those lines. I would like to allow html in this field and a quick googling hasn't helped much. Maybe I'm searching for the wrong terms.

我想禁用此字段的字符转义符,并且可能只允许少量选择html标签.在Symfony中执行此操作的正确方法是什么?

Anywho I would like to disable character escaping for this field and possibly only allow a small selection of html tags. What is the correct way to do this in Symfony?

推荐答案

来自 http: //www.librosweb.es/symfony_1_1_en/capitulo7/output_escaping.html

每个模板都可以访问$ sf_data变量,该变量是引用所有转义变量的容器对象. [跳过] $ sf_data还使您可以访问未转义的或原始的数据.如果您信任该变量,则当变量存储要由浏览器解释的HTML代码时,此功能很有用.需要输出原始数据时,调用getRaw()方法.

Every template has access to an $sf_data variable, which is a container object referencing all the escaped variables. [skipped] $sf_data also gives you access to the unescaped, or raw, data. This is useful when a variable stores HTML code meant to be interpreted by the browser, provided that you trust this variable. Call the getRaw() method when you need to output the raw data.

echo $ sf_data-> getRaw('test'); => alert(document.cookie)每次需要将包含HTML的变量真正解释为HTML时,都必须访问原始数据.现在,您可以理解为什么默认布局使用$ sf_data-> getRaw('sf_content')来包含模板,而不是使用更简单的$ sf_content,后者在激活输出转义时会中断.

echo $sf_data->getRaw('test'); => alert(document.cookie)You will have to access raw data each time you need variables containing HTML to be really interpreted as HTML. You can now understand why the default layout uses $sf_data->getRaw('sf_content') to include the template, rather than a simpler $sf_content, which breaks when output escaping is activated.

这篇关于如何在Symfony 1.2的表单字段中允许某些HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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