I am wanting to build a basic theme with a default config file and then I want to build sub themes with config files that are merged with the master theme. Should I use the Kohana::config class to manage this or would it be best to handle this manually by including the config array and merging it with the master config? So far I haven’t been able to get the config files to load at all because I’ve got them located within their own directory.
Basically What I’m trying to do is setup a structure like:
application
|--> classes
|--> myclass
|--> myclass.php // default parent class. Loads the config
|--> config.php // array of default config settings
|--> theme
|--> blue
| |--> blue.php // extends myclass.php
| |--> config.php // merges over the default config settings
|--> red
| |--> red.php // extends myclass.php
| |--> config.php // merges over the default config settings
|--> green
|--> green.php // extends myclass.php
|--> config.php // merges over the default config settings
So I can then call something like:
$theme = new Myclass_Theme_Red_Red();
and have the theme loaded with the default configs from Myclass_Myclass and then have the red theme merged over the defaults. I hope this make sense.
So what is the best way of handling config settings within this sort of structure – or is there a better approach entirely? I don’t want to move all the config files into application/config as I would prefer them to be kept with the individual themes.
I’d put the config files into a config directory which is a sibling of the classes directory.
So your new directory structure would be:
This is where your configuration files should always go. If you need to do something which Kohana doesn’t support then you can add a custom config reader in your (modules) bootstrap [1].
[1] Attaching a new config reader in Kohana
A common example would be to load config files from a sub-directory which can be achieved with:
This allows me to use different config settings per environment with Kohana.
If you desperately want to keep your config files with the classes you might want to make each theme a separate module.