0

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?

Daniel Standage
  • 8,136
  • 19
  • 69
  • 116

2 Answers2

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.

1ed
  • 3,668
  • 15
  • 25
1

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.

Community
  • 1
  • 1
Vlad Jula-Nedelcu
  • 1,681
  • 11
  • 17