Fegg Coding Guide
info
This is the guide for Fegg 5. If your project still uses Fegg 4 (fegg/ and code/ directories), switch to Fegg 4.x in the version dropdown in the navbar.
About Fegg
Fegg is a small PHP framework, originally created by Genies, Inc. and extended by LionHeart with a CMS foundation (login, media and image management, post types).
LionHeart projects start from the skeleton repository lionheart-group/lh-fegg-skelton. It contains Fegg, the CMS, sample pages (top page, news, contact form) and the frontend build setup.
Features
- PHP 7.4 to 8.5 are supported.
- Core and site are separated.
htdocs/_fegg/core/is the core: the framework and the CMS foundation shared by every project. Do not edit it.fegg-cli core:updatereplaces it as a whole, the same way you update WordPress itself.htdocs/_fegg/site/is the site: your project's controllers, templates and settings. Updates never touch it.- To change something the core provides (a CMS template, a CMS screen, a setting), override it from
site/.
- Several sites in one project. Each site (the site at
/, a recruiting site at/recruit/...) has its own folder of templates, SCSS, JS and images insite/template/<site>/(see Sites). A site without the CMS turns it off with$settings['cms'] = false. - Namespaces and autoloading. Controllers are
Site\Controller\...classes and framework classes areFegg\...(Fegg\Model,Fegg\Tool\Validation,Fegg\Tool\Mail, ...). Create classes withnew. - Errors fail loudly. Database errors throw
Fegg\Database\QueryExceptionand missing templates throwFegg\Template\TemplateException. Uncaught, both become a logged HTTP 500 (the error pagesite/template/error/500.htmlcan be your own).Fegg\Logwrites the application log. - Per-server settings and secrets come from
site/config/env.php(not committed) or environment variables, read withfeggEnv().FEGG_ENV(productionunless set) decides whether developers see error details. - Secure by default. Security headers on every response, sessions only when needed (
HttpOnly,SameSite=Lax, strict mode), CSRF tokens in the CMS, login throttling, upload content checks. - SQLite or MySQL.
fegg-cli migrationworks on both. - A modern CMS. The CMS's scripts are plain JavaScript. Rich text fields use FeggEditor (Tiptap), with columns, galleries, buttons, maps and links to files, and the saved HTML is cleaned on the server. The icons are Tabler Icons. See CMS screens and the editor.
- Command line tools.
fegg-clichecks templates (template:lint), lists the database schema (db:schema), adds sites (site:create), manages CMS users (user:create), updates the core (core:update) and checks that_fegg/cannot be read from the web (doctor).
Fegg 3 / 4 projects are rebuilt from the skeleton: see Moving a Fegg 3 / 4 project.
Where to start
- Directory structure: what lives in
core/andsite/ - Settings:
site/config/settings.php,env.phpand the database connection - fegg-cli: command line tools
- Updating the core
- Moving a Fegg 3 / 4 project
- URL and Controller: how a request reaches your code
- Security and Logging and errors
- CMS screens and the editor: the CMS's scripts, icons and rich text fields