Welcome Guest, Not a member yet? Register   Sign In
Views or templates in database?
#1

[eluser]Tookings[/eluser]
This may be answered somewhere...but I couldn't find it. Feel free to tell me to search better. Smile

Has any done or developed anything to store views (well, really view templates) in a database?

I usually end up writing my own lightweight template systems for very customized applications -- and in CodeIgnitor I use two views together, one is a fairly generic "template loader" view with PHP code that calls parse() on a second HTML-only view "template".

However...for multi-domain sites managed from one master location (many duplicated identical public codebases, with one admin codebase) other than 1 or 2 values in a config file, I keep everything in one database and all the code completely generic between the sites. Once a change on the QA code is ready, a script pushes new code out to all the sites at once. This works well -- but designers updating the base templates need an easier way to modify them without pushing out multiple files or even needing FTP access.

Just curious if anyone had already done this...I'll probably just modify the parse function to load templates from a table instead of views. (Since the designers don't need access to the PHP template loader view.) But I was curious if anyone had redone ALL view functions to pull their code/content from tables? And...if so, why?

Or if this was a terrible idea. I haven't slept in a 30 hours or so. Smile

Thanks!
#2

[eluser]Tookings[/eluser]
Seems like taking all views to the DB wouldn't be a good idea -- but markup templates, with no PHP in them, are working great for my particular application.

Just did something like this in an extended parse() function:

Code:
if($useDB === FALSE)
   {  
   $template = $this->CI->load->view($template, $data, TRUE);
   }
elseif($useDB === TRUE)
   {
   //NOTE: build a model somewhere to load the template
   $template = $this->CI->pagemachine_model->getTemplate($template);
   }

Random thought...anyone else use "Whitesmiths style" of indenting, as it seems to be called? Doesn't seem very common at all -- but I love it. Smile
#3

[eluser]Alexandros Monastiriotis[/eluser]
Hi Tookings,

nice post and in my opinion its a hard topic. If i understand well, you need to avoid file html templates and store them in a table in database. Is that correct?

Have u seen smarty php template engine? I dont know if you are able to store the templates in a db though.

But if you develop large web sites with a lot of visitors maybe you have to avoid loading the template from database, and parse it. Just a thought i am not saying it is 100% correct.

Maybe you need to develop a CMS and the designers can edit templates through a web interface. It can be done easily you know. They may also edit the css of the site like this. Like Joomla! CMS where you can edit the templates and the css.

I am sure all the above i wrote, you have already though about.

But definitely if you sleep i am sure you will find the best suitable solution. :-D

Take care

Alex




Theme © iAndrew 2016 - Forum software by © MyBB