views:

150

answers:

1

I am developing application, where i want to make theme independent of system in code igniter.

these themes are just css files and images, not necessarily views. in codeigniters MVC.

these theme shall be selected by database variable.

how can id do this?

+2  A: 

Store the name of the used theme in user sessions. Then in each controller constructor check for existence of the value, check in your database for the existence of the theme name, and give the data to the view, who in turn handles the thing via included headers.

The database will look like this:

theme_id | theme_name | theme_css 
------------------------------------
1        | default    | default.css
2        | fancy      | fancy.css

Your views will all contain something like this:

<?php include header.php ?>

header.php will contain this:

<link href="/css/<?=$theme_data->css?>" rel="stylesheet" type="text/css" />

And your base controller that extends the standard controller will look something like this:

<?php
class Base_Controller extends Controller
{
    protected $theme = 'default';
    function __construct()
    {
     parent::Controller();
     if ($this->session->userdata('theme')
     {
      $this->theme = $this->session->userdata('theme');
     }
     $this->view->data['theme_data'] = $this->get_theme_data();

    }

    protected function get_theme_data()
    {
     // return data from database using $this->theme
    }

}
Residuum