laika-framework

Laika Framework Documentation

Laika is a lightweight Moduler First MVC framework for PHP 8.1+. Requests flow through pipelines (middleware before the controller), the controller, and filters (middleware after it), backed by a query builder, Twig templates, a service container and a code-generating CLI. Everything ships as small Composer packages under vendor/laikait/.

New to Laika? Read Getting Started in order. Looking for something specific? Try the common tasks table.


Getting Started

Guide Covers
Installation Requirements, Composer install, the dev server
Project Structure What every directory is for
Configuration lf-config/*.php, config(), lf-inc/const.php
CLI Reference All 46 php laika commands, writing your own
Request Lifecycle What runs, in what order, from public/index.php to the response
Upgrading Moving to laika-core 5.1

The Basics

Guide Covers
Routing Routes, parameters, named routes, groups, fallbacks
Controllers Return values, parameters, dependency injection
Requests Input, files, headers, validation
Responses JSON, status codes, redirects, flash messages, cookies, downloads
Pipelines Middleware that runs before the controller
Filters Middleware that runs after the controller
Templates Twig views, template variables, filters
Assets, Meta & Navigation Styles, scripts, meta tags, context, menus, icons

Database

Guide Covers
Models & Database Connections, models, schemas, migrations, soft deletes
Query Builder Every query, connection and schema-builder method
Backup & Convert Database backups, moving between database engines

Architecture

Guide Covers
Services & Relays The container, providers, relays, auto-wiring
Relay List Every Laika\Engine\Services\* relay
Hooks lf-hooks/, add_hook() / do_hook() / apply_hook()
Resources How classes are discovered; adding your own resource types
Helper Functions Every global helper function

Security

Guide Covers
Authentication Session, cookie and token guards
Security (Shield) Firewall — rate limiting, IP/country blocking, SQLi/XSS detection
CSRF & CORS CSRF tokens, CORS and security headers
Encryption & Tokens App key, encryption, password hashing, JWTs, IDs

Beyond the Request

Guide Covers
Sessions File, database, Redis and Memcached sessions
Session Drivers & Operations Locking, garbage collection, failure modes, several servers
Queue Background jobs and the worker
Queue Drivers & Operations Driver internals, stuck jobs, worker hooks, custom drivers
Caching File, Redis and Memcached caches; query, response and template caching
Mail Sending and reading email
Files & Storage Uploads, images, files, local and S3 storage
Errors & Logging The error handler, HTTP exceptions, logs, activity log, options
Utilities Dates, precise math, cron, shell commands, IP maths
Extending the Framework Custom drivers, macros and subclassing framework classes

Operations

Guide Covers
Deployment Apache, nginx, PHP-FPM, production checklist, running the worker

Common Tasks

I want to… See
Add a page Routing → Controllers → Templates
Validate a form and show errors Requests → Validation
Return JSON from an API Responses → JSON
Redirect with a flash message Responses → Redirects
Protect routes with a login Authentication → Protecting Routes
Issue API tokens Authentication → Token Guard
Check CSRF tokens CSRF & CORS → CSRF
Allow another origin to call my API CSRF & CORS → CORS
Rate-limit or firewall the app Security (Shield)
Create a table Models → Schemas
Query the database Query Builder
Use a second database Models → Multiple Connections
Store something in the session Sessions
Upload a file Files & Storage → Upload
Send an email Mail
Run work in the background Queue
Fix a queue that stopped processing Queue Drivers & Operations → A Job That Can’t Be Restored
Cache a slow value, query or page Caching
Run code on every request Hooks → Hook Files
Make a service available everywhere Services & Relays
Add my own cache, session, queue, database or mail driver Extending → Custom Drivers
Add a method to Model, Request or Response Extending → Macros
Add my own php laika command CLI → Writing Your Own Commands
Change the timezone Utilities → Date
Go to production Deployment

Package Reference

The whole framework ships in one package, laikait/laika-engine. These docs explain how its modules fit together inside an application; the engine’s docs/<module>/ folders go deeper into their internals:

Module Namespace Provides
Core Laika\Engine\* (App, Http, Helper, Support, …) Bootstrap, request/response, validation, templates, helpers, storage, security, errors
Route Laika\Engine\Route Router, dispatcher, pipelines and filters
Model Laika\Engine\Model PDO query builder, schema builder, backup, SQL converter
Relay Laika\Engine\Relay, Laika\Engine\Services Service container, relay base class and the core service relays
Session Laika\Engine\Session File, database, Redis and Memcached session handlers
Auth Laika\Engine\Auth Session, cookie and token guards
Shield Laika\Engine\Shield Firewall pipeline (rate limiting, IP/country blocking, SQLi/XSS detection)
Queue Laika\Engine\Queue Background job queue and worker
Cache Laika\Engine\Cache Cache drivers: file, array, Redis, Memcached
Mailman Laika\Engine\Mailman Mail sending (PHPMailer) and IMAP/POP3 reading
Cli Laika\Engine\Cli The laika command-line tool

Where a package README and these docs disagree about behaviour inside a Laika app, these docs describe the current code.

Getting Help