简体   繁体   中英

Disable escaping for admin generator list action?

I am configuring Symfony 1.4's admin generator for one of my data models ("Achievement"). 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. 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").

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. 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. Is there no finer-grained control of escaping for Symfony 1.4?

You should not generate HTML in model. 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. See my answer to this question.

But, like 1ed said, you better make a helper for this, not write html code in your controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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