Getting Started
A site is a folder with core at core/. One script builds the rest of the folder, and nothing is installed globally.
Requirements
| What | Why | Source |
|---|---|---|
| PHP 8.0 or newer | Attributes, and the version core declares | core/composer.json |
A web server that sends every URL that is not a file to index.php |
The front controller answers every page. Samples for Apache (mod_rewrite) and nginx are included |
core/skeleton/frontend/www/.htaccess, core/skeleton/etc/ |
| git and bash | Core is a git submodule of the site; zero-init.sh is a bash script |
core/skeleton/README.md |
| A database, for anything with accounts | Sign-in, permissions and the admin screens read the tables core/sql/core.sql creates. A site of pages that run no query needs none (see below) |
core/sql/README.md, core/Database.php |
Composer and npm are not required. Core loads its own classes and every module's by namespace (Autoloading).
Start a Site
The site is a repository with core as a submodule at core/. Core has a submodule of its own, core/entity/, which sign-in needs, so the update is --recursive.
git init mysite && cd mysite git submodule add <zero.core repository> core git submodule update --init --recursive core/skeleton/zero-init.sh # or: core/skeleton/zero-init.sh /path/to/site mysite.com
zero-init.sh takes two optional arguments: the site directory (default: the folder that contains core/) and the domain. Without a domain, the folder's name stands in for PRIMARY_DOMAIN and the script says so.
What zero-init.sh Creates
mysite/
├── core/ already there: the framework
├── etc/ apache.conf, apache-ssl.conf, nginx.conf for the domain
├── entity/ the site's own entity classes (empty)
├── modules/ the site's own modules (empty)
├── storage/cache/ what core caches; the web server writes here
└── app/
├── config/ config.ini, constants.ini, database.ini, allowed-ips.lst
├── strings/site.ini the site's wording
├── modules.ini which modules are on
├── .gitignore modules.ini.lock and .modules.ini.*.tmp
└── frontend/
├── frame/ head, header, sideNav, footer and the partials
└── www/ web root: index.php, .htaccess, assets/css/main.css
- Everything is copied from
core/skeleton/. The script clones nothing and needs no root. - A file that already exists is skipped and named in the output, so running the script again is safe.
- In a
config.iniit has just created, it replacesexample.comwith the domain and setsWEB_ROOTto the site'sapp/frontend/www. - In a
site.iniit has just created,SITE_NAMEbecomes the domain. - The vhost samples in
etc/are written with the domain and the site path filled in. storage/cache/is created with mode 775.modules/is empty: core's ownIndexserves/until the site has one (Bundled Modules).
The Web Root's index.php
Four constants, one include, four calls. This is core/skeleton/frontend/www/index.php, the file the script copies to app/frontend/www/index.php:
<?php
// Zero Framework Bootstrap
// ZERO_ROOT is the folder three levels above www/ (app/frontend/www inside the
// zero root), whatever the site folder is called.
define("ZERO_ROOT", dirname(__DIR__, 3) . "/");
define("ROOT_PATH", dirname(ZERO_ROOT) . "/");
define("VIEW_PATH", ZERO_ROOT . "app/frontend/frame/");
define("MODULE_PATH", ZERO_ROOT . "modules/");
require ZERO_ROOT . "core/Application.php";
$app = new Zero\Core\Application();
$app->registerAutoloaders();
$app->parseRequest();
$app->defineConstants();
$app->run(
\Zero\Core\Request::$module,
\Zero\Core\Request::$endpoint,
\Zero\Core\Request::$args
);
| Constant | Is |
|---|---|
ZERO_ROOT | The site root, the folder that holds core/ |
ROOT_PATH | Its parent |
VIEW_PATH | The site's frame folder, app/frontend/frame/ |
MODULE_PATH | The site's modules/ folder |
What each of the four calls does is on Routing.
Next Steps
The script prints these when it finishes:
- Fill in
app/config/database.ini:NAMEandUSERare blank in the template, and nothing connects until they andDB_DRIVERare set. Check the domain and mail addresses inapp/config/config.ini. Every key is on Configuration & Wording. - Create the tables core needs by loading
core/sql/core.sqlinto an empty database. It usesCREATE TABLE IF NOT EXISTSand never drops, truncates or updates, so loading it again is safe (core/sql/README.md). - Make
storage/cache/writable by the web server user. - Install a vhost from
etc/. The document root isapp/frontend/www/. - Open the site, then build modules in
modules/.
mysql <database> < core/sql/core.sql
Running Without a Database
Core opens no connection until code asks for one: Database::getConnection() connects on its first call (core/Database.php). The one check every request makes, Session::endIfDisabled() in Application::run(), returns before any query when nobody is signed in.
With DB_DRIVER, NAME or USER blank in database.ini, no connection is ever attempted: getConnection() throws Database is not configured and logs nothing. So with NAME and USER left blank, as the template has them:
- Core's
Indexpages (/and/privacy) and any module of your own that runs no query work normally. This site runs that way. - Sign-in,
#[RequirePermission], API tokens and the admin screens do not: they read the tables incore.sql. - With the modules at their defaults,
/user/loginstill renders. Its sign-in buttons ask the Auth module's provider registry, which queries; the skeleton's_oauth-buttons.phpcatches the exception and shows no buttons. No connection is tried and no log line is written. - A site with no sign-in turns those modules off in
app/modules.ini. This site's file hasAuth,User,Admin,PushandEntityalloff, so/user/loginand/adminare 404s here (Bundled Modules).
Composer Packages
core/composer.json lists the packages core uses and does not bring with it. Nothing reads that file at runtime: it documents what to install, and a site requires the packages in its own composer.json.
| Package | Listed under | Needed by |
|---|---|---|
minishlink/web-push ^8.0 |
require |
The Push module |
google/apiclient ^2.18 |
suggest |
The Auth module's Google sign-in |
Application::registerAutoloaders() includes vendor/autoload.php from ROOT_PATH and from ZERO_ROOT when either exists. A site that uses neither package needs no vendor/ folder.
What a Site May Leave Out
core/skeleton/ is also the default core falls back to. A site overrides by having the file or the key:
| Missing from the site | Core uses |
|---|---|
A frame piece (head, header, sideNav, footer) or a partial (_head-scripts, _oauth-brand, _oauth-buttons, _google-signin) |
The copy in core/skeleton/frontend/frame/ |
A config file named constants.ini or error_codes.ini in app/config/ |
The file of that name in core/skeleton/config/ (Application::configFiles()) |
| A wording key | The value in core/skeleton/strings/site.ini (Strings::loadDefaults()) |
modules/Index/ |
core/modules/Index/ |
app/modules.ini |
Every module at its tier's default |
Frame lookup is on Views & Frames; config and wording on Configuration & Wording.
A First Module
mkmod scaffolds a module into the site's modules/ folder, never into core/. The name is StudlyCaps and may not be one a bundled module has: an override of a bundled module is written by hand.
core/modules/Module/mkmod Weather
With no flags it writes Weather.php, view/index.php, assets/css/weather.css, assets/js/weather.js and a .gitignore. The module is on by default and answers at /weather on the next request. mkmod --help lists the flags for the optional directories.