[eluser]jedd[/eluser]
My themes are stored under /assets. At the moment they're a bit dodgy, as I organised them the wrong way around - theme name should be higher in the hierarchy rather than replicated lower in multiple hierarchies. But it serves as a workable example.
My default view file (used for displaying every page) includes this preamble:
Code:
<html>
<head>
<?php
// $theme is set in MY_Controller, taken from session variable
echo "\n". link_tag('assets/stylesheets/COMMON.css');
echo "\n". link_tag('assets/stylesheets/'. $theme .'.css');
// favicon being themed is of .. lesser usefulness, but, hey, why the heck not?
echo "\n". link_tag('assets/icons/'. $theme .'/FAVICON.png', 'shortcut icon', 'image/ico');
?>
MY_Controller mechanism is used to set the theme as part of the session userdata - this is set at login(), but I cater for a default theme here (note the reference back to the config.php file - one line entry there for default theme)
Code:
class MY_Controller extends Controller {
function MY_Controller () {
parent::Controller();
// We need a theme, any theme! If we don't have one set, set one.
if ($this->session->userdata("theme") == NULL)
$this->session->set_userdata ("theme", $this->config->item('pdb_default_theme'));
$this->data['theme'] = $this->session->userdata('theme');
Note the last line there pushes the chosen theme into the $this->data array that will end up feeding the view (above). I occasionally use $this->data['theme'] elsewhere - though as it happens, not as often as I expected - most stuff happens in the CSS. The places I use it most are when prefacing anchors to icons and the like.
Users can select a theme - they are named in the database table
theme : [ id , name , longname , description ] - where 'name' refers to the subdirectory/ies in my assets structure. Obviously I have a int field in my
user table to denote theme.id