php fetchone(),php – symfony 1.4解释并且不会在模板中使用fetchOne()显示html标签

我有以下设置:php 5.4,symfony 1.4.17和firefox,即chrome.

我已经构建了一个简单的新闻模块.

>表:TbNews

>列:

> id作为主键

> scontent作为保存新闻内容的文本字段.它将内置html内容,与CKeditor一起保存,并且完美运行.

如果我使用fetchOne()(在模板中),则在写入内容之前解释html.

如果我使用symfony pager(在行动中,然后是模板),则不会解释html,并且我会在输出中看到带有内容的HTML标记.

你可以看到下面的例子,它们显示我正在谈论的内容.

我已阅读其他主题,出于安全原因,symfony输出escaper会自动将HTML转换为“text”,我们必须对数据使用getRawValue来获取原始HTML字符.

我有一些问题:

>为什么symfony输出escaper正在使用symfony pager及其

如果我们使用fetchOne()不工作?

>我应该如何使用symfony在下面的示例中使用getRawValue()

寻呼机,解释HTML,然后只显示内容?

> getRawValue()是获取仅写入内容的最佳选择吗?

示例代码:

//1. fetchOne() outputs content interpreting html before.

//index/templates/indexSuccess.php

//-------------------------------

$q = Doctrine_Query::create()->from('TbNews e')->where('e.id = ?', '1');

$new = $q->fetchOne(); //

testcontent

\r\n

echo $new['scontent'];

// output: testcontent --- OK, output is not escaped because we are jumping symfony output escaper since we are doing it directly in the action.

//2. Get all news with symfony pager, html tags are not interpreted, html tags are shown.

//index/actions/actions.class.php

//-------------------------------

$app_max_news_in_homepage = 4;

$this->pager = new sfDoctrinePager('TbNews', $app_max_news_in_homepage);

$this->pager->setQuery(Doctrine::getTable('TbNews')->createQuery('a'));

$this->pager->setPage($request->getParameter('page', 1));

$this->pager->init();

//index/templates/indexSuccess.php

//--------------------------------

foreach ($pager->getResults() as $new)

{

echo $new['scontent']; // <p>testcontent</p>\r\n

}

//output:

testcontent

--- OK, since output is escaped by symfony output escaper since we get data at the action and show it in the template.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值