代码之家  ›  专栏  ›  技术社区  ›  Alexander Morland

如何将HTML存储在Doctrine YML fixture中

  •  2
  • Alexander Morland  · 技术社区  · 7 年前

    我在symfony 1.4(原则1.2)中使用一个cms类型的站点,让我感到沮丧的一件事是不能在yml fixture中存储html页面。相反,如果我想删除和重建数据,我必须创建数据的sql备份,当symfony/docine有一个非常好的机制来完成这项工作时,这有点麻烦。

    我可以编写一种机制,为每个页面读入一组html文件,并以这种方式填充数据(甚至作为任务编写)。但在我走这条路之前,我想知道是否有办法将html存储在一个yml fixture中,这样docine就可以简单地将它导入数据库。

    更新:

    我试过用 symfony doctrine:data-dump symfony doctrine:data-load 然而,尽管dump使用html正确地创建了fixture,加载任务似乎“跳过”使用html的列的值,并将其他所有内容输入到行中。在数据库中,该字段不会显示为“null”,而是空的,因此我相信Doctrine正在将列的值添加为“”。

    下面是YML设备的一个示例 symfony学说:数据转储 创建。我试过跑步 symfony原则:数据加载 反对各种形式的这种做法,包括删除所有转义字符(新行和引号只留下尖括号),但仍然不起作用。

      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
    
    2 回复  |  直到 9 年前
        1
  •  4
  •   Amy B    16 年前

    你能用下面的格式吗?

      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
    
        2
  •  2
  •   jDutton    16 年前

    我也有类似的问题,我发现 存储 数据库中的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