次のセットアップがあります: php 5.4、symfony 1.4.17、および firefox、つまり chrome。
簡単なニュースモジュールを作成しました。
- テーブル:
TbNews
- 列:
id
主キーとしてscontent
ニュースコンテンツを保存するためのテキストフィールドとして。内部にhtmlコンテンツがあり、CKeditorで保存され、完全に機能します。
(テンプレートで)使用するfetchOne()
と、コンテンツを書き込む前にhtmlが解釈されます。
symfony ページャーを使用すると (実際には、テンプレート)、html は解釈されず、コンテンツと共に出力に HTML タグが表示されます。私が話していることを正確に示す以下の例を見ることができます。
セキュリティ上の理由から、symfony の出力エスケーパーは自動的に HTML を「テキスト」に変換し、データで getRawValue を使用して元の HTML 文字を取得する必要があることを他のトピックで読みました。
- テンプレートで html タグを表示 - symfony と CKEDITOR。安全性は?
- symfony がクエリ結果から html をエスケープしないようにする
- Symfony.com ビュー レイヤー出力のエスケープ
- Symfony sfOutputEscaper メソッド getRawValue()
いくつか質問があります:
- symfony の出力エスケーパーが symfony ページャーで動作し、使用すると動作しないのはなぜ
fetchOne()
ですか? getRawValue()
以下の例で、symfony ページャーを使用して 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(); // <p>testcontent</p>\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: <p>testcontent</p> --- OK, since output is escaped by symfony output escaper since we get data at the action and show it in the template.