RU EN
Get started

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:

Structure
/                               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}.php

Site 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:

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 → output

How a request flows

  1. The web server serves existing files (CSS, JS, images) directly and sends everything else to index.php.
  2. kernel::init() remembers the site root, registers the autoloader and the system route /system/:controller/:action.
  3. config.php defines settings, the layout and custom routes.
  4. kernel::run() asks the router to find a controller: custom routes are checked first, then the URL is parsed as /module/controller/action.
  5. The router loads the controller file — first from site/modules, then from olala/modules — creates the object and calls the action method.
  6. Whatever the action returns (a string) is inserted into the layout as $content by view::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:

ClassFile
olala\modules\cacheolala/modules/cache.php
site\models\Postsite/models/Post.php
site\services\Mailersite/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 example site/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.