Welcome Guest, Not a member yet? Register   Sign In
Setting site url inside text content from a database
#1

[eluser]Andy UK[/eluser]
I'm programming a simple blog for my website and I'm not sure how to set the site url inside a post content.

The body of the post is stored in a text field in the relevant table of my database, and often I will include images in a post. Rather than using relative directory syntax or hardcoding the url of the image, is there a way to set some kind of site url constant or something?

Example post body text:

Code:
<p>Some introduction text. This is the post content dynamically loaded from the database.</p>

<img src="../resources/blog/2010/12/myImage1.jpg" />
<img src="../resources/blog/2010/12/myImage2.jpg" />

<p>Some closing text for this particular post.</p>

At the moment I'm quite happy typing in the p tags and the img tags. I just need a way to set the site url so that I don't have to edit every single post should I ever change domains or change the location of the blog image directory.

Thanks!
#2

[eluser]2think[/eluser]
You could use the Codeigniter URL Helper. Don't forget to load it in your controller or autoload in your autoload file.

Then, you just do &lt;?php echo site_url("controller/function/xyz"); ?&gt;

http://ellislab.com/codeigniter/user-gui...elper.html
#3

[eluser]Andy UK[/eluser]
Thanks, but I'm already using the url helper all over the site and it works fine. The issue here is that the paths are contained within a text field loaded from the database. Even If I try and put php tags in the body text, It just gets echoed as is, without any php interpretation taking place.

To reiterate, the paths are within the body text of a post and are contained in the database. They are not part of any controller, view or model.

Andy.




Theme © iAndrew 2016 - Forum software by © MyBB