CodeIgniter Forums

Full Version: Database text and PHP code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm sure this is an old chestnut but I am building a simple CMS to hold page text. The problem is that the pages currently use CI helper functions eg base_url() for image paths and safe_mailto() for mail links, . When the mysql db spits out the page of text, the php code obviously appears as plain text so that's not going to work. I can go the route of not using these helper functions but then I lose some CI functionality and create more work.

I've explored echoing the db text within eval() but it includes html tags and they cause PHP to throw an error.

As this must be an old and well-known problem, I wonder if there is an equally well-known standard workaround. I have been unable to find anything with Google so I hope some forum member can help me - even if only to say 'stop wasting time, it's impossible'
You could use the template parser ...

Retrieve the "page" from the database, and run the result through the template parser to get the desired HTML.
Brilliant - thanks so much. I've never used the template parser and I'd forgotten it existed. That is a solution!