Documentation Getting started
Project structure
Which files live in the root, what goes where and how a request flows through.
Files and folders
An olala site is a site root with three service files, the framework folder olala/ and your own site/ folder:
/ site root (document root)
├── index.php entry point: every request comes here
├── config.php DEBUG, settings, layout, routes
├── .htaccess URL rewriting for Apache
├── create -> olala/console/create
├── cache/ file cache (created when needed)
│
├── olala/ the framework — updated separately, don't put your code here
│ ├── kernel.php startup, autoloading, error handling
│ ├── router.php URL parsing, loading the controller
│ ├── controller.php base controller and render()
│ ├── view.php layouts and output
│ ├── modules/ db, cache, Session, settings, date, image, email…
│ ├── exceptions/ NotFoundException
│ ├── web/ system.js, view.js, system.css
│ └── console/create console utility
│
└── site/ your site
├── layouts/
│ ├── default/index.php main layout
│ └── ajax/index.php “empty” layout for AJAX responses
├── models/ models (namespace site\models)
└── modules/
└── {module}/
├── controllers/{controller}Controller.php
└── views/{template}.phpSite code is completely separated from the framework. To update olala, just replace the olala/ folder — your modules, models and layouts stay untouched.
Entry point
The whole site starts with a short index.php:
<?php
setlocale(LC_ALL, 'ru_RU.utf8');
include('olala/kernel.php');
olala\kernel::init(); // site root, autoloader, system route /system/…
require __DIR__ . '/config.php'; // your settings and routes
olala\kernel::run(); // routing → controller → layout → outputHow a request flows
- The web server serves existing files (CSS, JS, images) directly and sends everything else to
index.php. kernel::init()remembers the site root, registers the autoloader and the system route/system/:controller/:action.config.phpdefines settings, the layout and custom routes.kernel::run()asks the router to find a controller: custom routes are checked first, then the URL is parsed as/module/controller/action.- The router loads the controller file — first from
site/modules, then fromolala/modules— creates the object and calls the action method. - Whatever the action returns (a string) is inserted into the layout as
$contentbyview::display()and sent out.
Class autoloading
The olala autoloader is as simple as it gets: it replaces \ in a class name with /,
appends .php and includes the file relative to the site root. So a class's namespace
must match its path:
| Class | File |
|---|---|
olala\modules\cache | olala/modules/cache.php |
site\models\Post | site/models/Post.php |
site\services\Mailer | site/services/Mailer.php |
Letter case matters: on Linux site\models\Post and site/models/post.php are different things.
Controllers are the exception: they are declared without a namespace and loaded by the router based on a naming convention. See Controllers for details.
Where to put your code
- Pages — in modules under
site/modules/…: a controller plus templates. - Data access — in models under
site/models/…. - Shared helpers and services — in any folder inside
site/, for examplesite/helpers/; just make sure the namespace matches the path. - Static files (CSS, JS, images) — in any public folder in the root, for example
assets/: the web server serves existing files itself, bypassing PHP.