开发者

How can I store HTML in a Doctrine YML fixture

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


Can you use this format below?

  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


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:

<?php echo $htmlText ?>

Use:

<?php echo $sf_data->getRaw('htmlText') ?>

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜