开发者

Symfony create links without http:// prefix

I use symfony 1.4.11/ U开发者_JAVA技巧ser on my site can add links to post like: http://stackoverflow.com/ , www.stackoverflow.com/ , stackoverflow.com/ And in my view I have:

<a href="<?php echo $companies->getUrl() ?>"><?php echo (__('Site')) ?></a>

When user post stackoverflow.com , I have relative URL , but I need absolute..Is there are way to resolve this?Thank you!


Why don't you create a custom validator, that automatically converts the user submitted address to a valid URI. (Always add the http(s):// part).

That way everything is stored the same way in your database (it all has exactly the same meaning), and no matter where you want to display an URL, you'll be sure it's valid.

Of course you could also override the $companies->getUrl() function to test if the URL is absolute, and if not add the protocol part. But then the data in your database still isn't stored 'the same way'.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜