Welcome Guest, Not a member yet? Register   Sign In
Database driven templating system
#11

[eluser]webdude[/eluser]
OK, so I am back looking at CI and am still wondering how to approach this. Any ideas?

Thanks

WD
#12

[eluser]Hermawan Haryanto[/eluser]
Hey webdude,

Few months ago I build a site, kind of a mix between youtube, multiply and flickr. Allowing member to run their own site which serve videos, photos, blogs, etc. In premium account I allow them to use their own HTML layout for their site.

I end up by making a table of templates for those premium accounts. I think the performance is quite stable. Just making a quick check if the member is premium or not, if it's premium, check if they already made a design of their own or not.

The only problem that I got is the premium member is sometime doesn't really understand HTML and they just upload what they made in dreamweaver to the form that I gave them, and the result is their site is broken and come back to me to fix it Big Grin.

So, I think, performance is not really a problem on the database driven template, instead it's the human knowledge of a template building.

Cheers,
Hermawan Haryanto
#13

[eluser]webdude[/eluser]
Hi Hermawan Haryanto

Thanks for the reply. How did you get the templates to work via a db? Would you be willing to share the code?

Thanks

WD
#14

[eluser]Hermawan Haryanto[/eluser]
I hope this code chunk is understandable.
Shoot me more if you don't understand some part of it

Model
Code:
/**
* Templates class
* /models/templates.php
*/
class Templates extends Model {
    /**
     * get_template
     *
     * @input key string
     * @output single object / false
     * @description
     *   To get an object of body template from database by given key
     */
    function get_template ($key)
    {
        $this->db->select ('body');
        $query = $this->db->getwhere ('template', array ('key' => $key));
        return ($query->num_rows() >= 1) ? $query->first_row() : false;
    }
}

Controller
Code:
/**
* Welcome controller
* /controllers/welcome.php
*/
class Welcome extends Controller {
    var $data;
    function Welcome ()
    {
        parent::Controller();
        $this->load->model ('Templates');
    }
    function index ()
    {
        $key = 'welcome_page';
        if ($template = $this->Templates->get_template ($key))
                $this->data['body'] = $template->body;
        else
                $this->data['body'] = $this->load->view ('template_not_found', $this->data, true);
        
        $this->load->view ('layout', $this->data);
    }
}
#15

[eluser]webdude[/eluser]
Thanks very much. I will try and have a look in the next day or two.

WD




Theme © iAndrew 2016 - Forum software by © MyBB