Getting started
Configuration
The Configure class
All configuration lives in a single in-memory array, read and written with dot-separated keys.
Configure::read('Templates.Theme'); // 'cgs'
Configure::read('Debug.Level', 0); // with a default value
Configure::check('Google.Recaptcha'); // does the key exist?
Configure::write('Templates.Site.phone', '...'); // creates missing levels
Configure::consume('flash_message'); // read and delete
Configure::delete('scripts');
Configure::merge(['Web' => ['SiteName' => 'X']]); // deep merge
It works the same way in Smarty: {Configure::read('Web.SiteName')}.
Tip
Configure also stores data for the current request: the route (System.Route), the added scripts and styles (scripts, styles) and the messages (flash_message, error_message).
How files are loaded
Koshkil::loadConfig() runs when core/Koshkil.php is included. For each file in the list it first loads the global version from config/ and then, if present, the domain's version. Each file defines a $CONFIG array that is deep-merged with what is already loaded, so a domain only needs to declare what changes.
Files loaded on every request, in this order:
config.phpdatasources.phpcache.phpextensions.phpsessions.phprewrite.phpi18n.php
For each one, the domain override is looked up in this order (the first that exists is used):
| Location | Example |
|---|---|
config/domains/cli/<file> |
only when SERVER_NAME is empty (command line) |
config/domains/<domain>/<file> |
config/domains/mysite.com/config.php |
config/domains/<domain>/<file>.php |
|
config/domains/<domain>.<file> |
config/domains/mysite.com.config.php |
config/domains/<domain>.php |
only for config.php |
Other files are loaded on demand: email.php when sending mail, google.php from SuperController, api.php from ApiService. You can load your own the same way:
Koshkil::loadConfig(['payments.php']); // config/payments.php + config/domains/<domain>/payments.php
Reusing another domain's configuration
A development domain can start from the production one by including its file before changing what's needed:
php
<?php
require __DIR__ . '/../mysite.com/config.php';
$CONFIG = array_merge($CONFIG, ['Debug' => ['Level' => 2, 'Javascript' => true]]);
Main keys
config.php
| Key | Purpose |
|---|---|
System.DefaultController |
Controller that answers when the URL matches none (default index). |
System.Text.MaxLength |
Maximum text length used by some utilities. |
Templates.Theme |
Folder in webroot/themes/ used by the public site. |
Templates.Menu, Templates.Site |
Data read by each theme's widgets and templates (menu, contact details…). |
Web.SiteName |
Site name. |
Debug.Level |
0 = no logs; 1 to 3 = logs with different masking of sensitive data; 6 = logs every SQL query; 7 = profiles every model. |
Debug.Rewrite |
5 or more logs the rewrite process to tmp/logs/rewrite.log. |
Debug.Javascript |
false makes WebElements::addScript() prefer the .min.js version when it exists. |
Debug.Profiler.Enabled |
Enables the timing profiler (see Cache, logs and debugging). |
Error.Reporting |
Value for error_reporting(). |
Log.MaxSize, Log.KeepHistory, Log.MaxHistory |
Log file rotation. |
Session.UserHandler.Frontend / .Backend |
Name of the session variable holding the user on the site and in the panel. |
datasources.php
$CONFIG = [
'Database' => [
'AutoUpdateSchema' => true, // keeps tables in sync with the models
'master' => [ // default connection
'Driver' => 'MySQLi', // MySQLi, PostgreSQL, SQLite, SQLServer, Oracle
'Host' => 'localhost',
'Port' => 3306, // optional
'Charset' => 'utf8mb4', // optional
'User' => '...',
'Password' => '...',
'Name' => 'my_db', // with SQLite: the file path
],
],
];
Other files
| File | Contents | More information |
|---|---|---|
cache.php |
Cache engines and domains | Cache |
sessions.php |
Session engine, cookie name, timeouts | Security |
rewrite.php |
System.Web.Rewrite: rewrite rules |
Routing |
i18n.php |
Languages, default language, detection | Internationalization |
extensions.php |
Extensions.Chat, Extensions.Ftp, Extensions.Pusher |
|
email.php |
Email.Smtp and sender |
Utilities |
google.php |
Google.Recaptcha.SiteKey and secret key |
Security |
api.php |
Credentials for the domain's internal API | REST API |
Credentials
datasources.php, api.php and email.php store passwords in plain text. config/ sits outside webroot/, but don't commit the real domains' files to the repository.