Documentation Tools
Configuration
config.php, DEBUG mode, the settings module and your own parameters.
The config.php file
config.php lives in the site root and is included from index.php after the core is initialized
but before the request is handled. Everything that configures the site is gathered here:
<?php
use olala\modules\settings;
use olala\router;
use olala\view;
const DEBUG = true; // detailed errors — for development only
settings::set([ // project parameters
'db_adapter' => 'pgsql',
'db_host' => '127.0.0.1',
'db_port' => '5432',
'db_name' => 'mysite',
'db_user' => 'mysite',
'db_pass' => 'secret',
'timezone' => 'Europe/London',
'site_name' => 'My site',
]);
view::$layout = 'default'; // default layout
router::addCustomRoute('/blog/:slug', [ // custom routes
'module' => 'blog', 'controller' => 'index', 'action' => 'show',
]);DEBUG mode
The DEBUG constant is required — the core uses it when handling errors:
true— on an exception, the file, line, message and full stack trace are shown;false— the visitor sees only the message text.
Before showing an error, the core writes it to the site.logs log via Log::error(). If the database isn't configured
or the table doesn't exist, writing to the log itself fails, and instead of a tidy message you'll get a fatal PHP error.
On a production site, connect the database and create the log table.
The settings module
olala\modules\settings is a simple per-request parameter store. Keys can be anything — add your own.
use olala\modules\settings;
settings::set('items_per_page', 20); // a single parameter
settings::set(['phone' => '+1 555 000-0000']); // several at once
settings::get('items_per_page'); // 20
settings::get('unknown'); // '' — the default value
settings::get('unknown', 10); // 10Parameters the framework reads
| Key | Where it's used |
|---|---|
db_adapter | PDO driver: pgsql or mysql; nodb — a site without a database |
db_host, db_port, db_name, db_user, db_pass | database connection, the db module |
timezone | time zone for date::format() |
access_log, log_format | the visitor counting console script olala/console/visitors_stat.php |
Other settings in config.php
| What | Details |
|---|---|
view::$layout = 'default' | Layouts |
router::addCustomRoute(...) | Routes |
view::$allowedViews = [...] | Rendering templates from JS |
Session::$engine = 'db' | Sessions in the database |
Development and production
A handy trick is to keep local differences in a separate file that doesn't go into the repository:
// at the end of config.php
if (file_exists(__DIR__ . '/config.local.php'))
require __DIR__ . '/config.local.php';In that case it's better to define DEBUG there — a constant can't be declared twice.