如何在 Doctrine YML 装置中存储 HTML
我正在 Symfony 1.4(Doctrine 1.2)中使用 CMS 类型的站点,令我沮丧的事情之一是无法在 YML 装置中存储 HTML 页面。相反,如果我想删除并重建数据,我必须创建数据的 SQL 备份,这有点麻烦,因为 Symfony/Doctrine 有一个出色的机制可以做到这一点。
我可以编写一种机制,读取每个页面的一组 HTML 文件并以这种方式填充数据(甚至将其编写为任务)。但在我走这条路之前,我想知道是否有任何方法可以将 HTML 存储在 YML 固定装置中,以便 Doctrine 可以简单地将其导入数据库中。
更新:
我尝试过使用symfonydoctrine:data-dump
和symfonydoctrine:data-load
但是尽管转储正确地创建了fixture HTML,加载任务似乎会“跳过”具有 HTML 的列的值,并将其他所有内容输入到该行中。在数据库中,该字段不会显示为“NULL”,而是显示为空,因此我相信 Doctrine 将该列的值添加为“”。
下面是 symfonydoctrine:data-dump
创建的 YML 夹具示例。我尝试过针对各种形式运行 symfonydoctrine:data-load ,包括删除所有转义字符(新行和引号仅留下尖括号),但它仍然不起作用。
Product_69:
name: 'My Product'
Developer: Developer_30
tagline: 'Text that briefly describes the product'
version: '2008'
first_published: ''
price_code: A79
summary: ''
box_image: ''
description: "<div id=\"featureSlider\">\n <ul class=\"slider\">\n <li class=\"sliderItem\" title=\"Summary\">\n <div class=\"feature\">\n Some text goes in here</div>\n </li>\n </ul>\n </div>\n"
is_visible: true
I am working with a CMS-type site in Symfony 1.4 (Doctrine 1.2) and one of the things that is frustrating me is not being able to store HTML pages in YML fixtures. Instead I have to create SQL backups of the data if I want to drop and rebuild which is a bit of a pest when Symfony/Doctrine has a fantastic mechanism for doing exactly this.
I could write a mechanism that reads in a set of HTML files for each page and fills the data in that way (or even write it as a task). But before I go down that road I am wondering if there is any way for HTML to be stored in a YML fixture so that Doctrine can simply import it into the database.
Update:
I have tried using symfony doctrine:data-dump
and symfony doctrine:data-load
however despite the dump correctly creating the fixture with the HTML, the load task appears to 'skip' the value of the column with the HTML and enters everything else into the row. In the database the field doesn't show up as 'NULL' but rather empty so I believe Doctrine is adding the value of the column as ''.
Below is a sample of the YML fixture that symfony doctrine:data-dump
created. I have tried running symfony doctrine:data-load
against various forms of this including removing all the escaped characters (new lines and quotes leaving only angle brackets) but it still doesn't work.
Product_69:
name: 'My Product'
Developer: Developer_30
tagline: 'Text that briefly describes the product'
version: '2008'
first_published: ''
price_code: A79
summary: ''
box_image: ''
description: "<div id=\"featureSlider\">\n <ul class=\"slider\">\n <li class=\"sliderItem\" title=\"Summary\">\n <div class=\"feature\">\n Some text goes in here</div>\n </li>\n </ul>\n </div>\n"
is_visible: true
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能使用下面这个格式吗?
Can you use this format below?
我遇到了类似的问题,我发现在数据库中存储 html 没有问题,但在 输出 html 中没有问题。 Symfony 似乎将 html 文本作为字符串输出,并在其周围加上引号,以防止跨站点脚本。然而,他们有办法渲染原始文本。而是使用:
使用:
您可以在《symfony 简介:第 7 章 - 视图层内部》中找到更多相关信息:
http://www.symfony-project.org/gentle-introduction/1_4/en/07-Inside-视图层
I was having a similar problem, and I found out that there is not a problem in storing html in the database but in outputting html. Symfony seems to output text with html as a string with quotes around it to prevent cross-site-scripting. However, they have a way to render the raw text. Instead using:
Use:
You can find out more about this in A Gentle Introduction to symfony: Chapter 7 - Inside The View Layer:
http://www.symfony-project.org/gentle-introduction/1_4/en/07-Inside-the-View-Layer