简体   繁体   English

为管理员生成器列表操作禁用转义?

[英]Disable escaping for admin generator list action?

I am configuring Symfony 1.4's admin generator for one of my data models ("Achievement"). 我正在为我的一个数据模型(“成就”)配置Symfony 1.4的管理生成器。 The "Achievement" data model has a field ("url") that stores a URL to an external resource, and I would like this URL to render as a link in the admin generator list action. “成就”数据模型具有一个字段(“ URL”),该字段存储指向外部资源的URL,我希望将此URL呈现为admin生成器列表操作中的链接。 By default, the admin generator displays the link as plain text. 默认情况下,管理生成器将链接显示为纯文本。 I tried writing a function to decorate the URL with HTML, and trim the string if it is too long (added to "lib/model/doctrine/Achievement.class.php"). 我尝试编写一个用HTML装饰URL的函数,并在字符串过长时对其进行修剪(添加到“ lib / model / doctrine / Achievement.class.php”中)。

function getLink()
{
  $text = $this->getUrl();
  if(strlen($text) > 40)
  {
    $text = sprintf( "%s...%s", substr($text, 0, 20), substr($text, -20, 20) );
  }

  return sprintf('<a href="%s">%s</a>', $this->getUrl(), $text);
}

Unfortunately, in the admin generator list view the HTML is escaped, leaving a long ugly string. 不幸的是,在admin生成器列表视图中,HTML被转义,留下了一个很长的丑陋字符串。 I cannot figure out how to disable escaping for this field. 我无法弄清楚如何禁用此字段的转义。

If I change "ESC_SPECIALCHARS" to "ESC_RAW" in "apps/backend/config/settings.yml", the link renders correctly. 如果我在“ apps / backend / config / settings.yml”中将“ ESC_SPECIALCHARS”更改为“ ESC_RAW”,则链接将正确呈现。 Is there no finer-grained control of escaping for Symfony 1.4? Symfony 1.4是否没有更精细的转义控制?

You should not generate HTML in model. 您不应在模型中生成HTML。 Instead create a helper function for that and make the field render as a partial and use the helper in it. 而是为此创建一个辅助函数,并使该字段呈现为局部,并在其中使用该辅助函数。

You can use sfConfig::set('sf_escaping_strategy', false) in your controller (actions.class.php) for list action. 您可以在控制器(actions.class.php)中使用sfConfig::set('sf_escaping_strategy', false) )进行list操作。 See my answer to this question. 请参阅我对这个问题的回答。

But, like 1ed said, you better make a helper for this, not write html code in your controller. 但是,就像1ed所说的那样,您最好为此做一个助手,而不是在控制器中编写html代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM