我正在使用Symfony 1.4(Doctrine 1.2)中的CMS类型站点,令我感到沮丧的一件事是无法在YML灯具中存储HTML页面。相反,如果我想删除和重建,我必须创建数据的SQL备份,这在Symfony / Doctrine有一个很好的机制来实现这一点时会有点害虫。
我可以编写一种机制,为每个页面读取一组HTML文件,并以这种方式填充数据(甚至将其写为任务)。但在我走这条路之前,我想知道是否有任何方法可以将HTML存储在YML夹具中,以便Doctrine可以将其简单地导入到数据库中。
更新
我已尝试使用symfony doctrine:data-dump
和symfony doctrine:data-load
但是尽管转储正确地使用HTML创建了fixture,但加载任务似乎用HTML“跳过”列的值并输入其他所有内容进入排。在数据库中,该字段不会显示为“NULL”,而是显示为空,因此我认为Doctrine正在将列的值添加为“”。
以下是symfony doctrine:data-dump
创建的YML fixture的示例。我尝试针对各种形式运行symfony doctrine: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
答案 0 :(得分:4)
您可以使用以下格式吗?
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">
<ul class="slider">
<li class="sliderItem" title="Summary">
<div class="feature">Some text goes in here</div>
</li>
<ul>
</div>
is_visible: true
答案 1 :(得分:2)
我遇到了类似的问题,我发现数据库中的存储 html没有问题,但输出 html。 Symfony似乎输出带有html作为字符串的文本,并在其周围加上引号以防止跨站点脚本。但是,他们有办法渲染原始文本。而是使用:
<?php echo $htmlText ?>
使用:
<?php echo $sf_data->getRaw('htmlText') ?>
你可以在一个温和的symfony简介中找到更多相关信息:第7章 - 在视图层内部:
http://www.symfony-project.org/gentle-introduction/1_4/en/07-Inside-the-View-Layer