Storing template views in a database |
[eluser]Unknown[/eluser]
Does anyone have any code related to storing template views in a database and then caching them locally? Smarty has functionality for this and I'm wondering how easy it is to do with CodeIgniter. Thanks!
[eluser]CI Begby[/eluser]
You will have to extend the view class to parse a string instead of reading from a file. This is not best practice security-wise though especially if you are planning on letting users edit the template. The entire template will end up being run through eval() which would allow someone to run any arbitrary code on your server, or if the db is compromised it will allow the same.
[eluser]Unknown[/eluser]
I realize there are security risks involved with letting users modify templates. I have a check set up to only allow certain HTML tags and template tags. That being said, how would I extend the view class without modifying any underline "CodeIgniter" code? Thanks!
[eluser]CI Begby[/eluser]
Look here for info on how to extend a core class. The one you want to extend would be CI_Loader. You can either override the view() method or add your own like view_from_string($templateString) or something. The latter option is probably best so that you can keep using the regular view method. You need to carefully review the view() method and understand it and make sure that your new method does a lot of the same stuff. That way you can still use the built in cacheing and your new views will work seamlessly with the rest of the framework.
[eluser]sophistry[/eluser]
if you are used to the fine-grained control that smarty offers in the caching dept. you will be surprised by how simple the CI caching mechanism is: cache per page only cache file in filesystem filename based on md5 hash of url only timestamp-based cache clearing (no up front code to remove cache on conditions) that said, there are offerings on the forums and the wiki that should get some of that smarty cache functionality. welcome to CI. |
Welcome Guest, Not a member yet? Register Sign In |