开发者

Symfony Routing; Internal URIs in User Generated Content

I am working on a Symfony (1.4) project which requires the user to be able to insert Internal URIs into the body of user generated content, writing within TinyMCE/WMD editor (haven't decided yet!) the user can add an internal URI to another place on the website. The content will be stored in the database as markdown/html.

I could simply insert the current URI retrieved through Symfony itself, but I was hoping there was a way to store the respective module/action/etc variables so that if the route needed to change, the URIs would remain correct throughout the website.

The only thing I can think of is a processor much like PHP Markdown, which performs a text search, extracting a custom mark-up within the content block, and replacing it with the markdown/html code for the generated route (using Symfony's get_url()/link_to() methods). [This would 开发者_StackOverflowalso require a text-mark-up generator, etc.]

Does Symfony have any other/better way than this? Can I access Symfony helpers/etc from within user generated input?


There's no easy way to do this. The best way is likely:

  • Parse the editor input on submission to find all URLs.
  • Replace URLs with a custom syntax that stores route name and parameters.
  • Whenever retrieving/displaying the information, remove your custom syntax and replace it with the generated route (e.g. via a preg_replace callback)

Alternatively, for small sites with relatively inflexible routes, it may be possible to display a drop-down list of available routes.

Either route will probably involve some headaches.


just tell users that they need to use named routes @my_custom_url and define them in symfony routing file routing.yml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜