Documentation
On this page
Install Cirth for CodeIgniter
CodeIgniter® serves public/, its web root, as it is. A web root is the
directory a browser can request files from. Cirth is one file there, linked
from a layout that every view extends.
Six steps: create the project, add the file, link it, write a view, run it in production mode and check it.
1 Create the project #
composer create-project codeigniter4/appstarter my-app
cd my-app
2 Add the file #
mkdir -p public/css
curl -o public/css/cirth.min.css \
https://cdn.jsdelivr.net/npm/@cirthcss/cirth@0.17.0/dist/cirth.min.css
Everything in public/ is reachable from the browser, and nothing else in
the project is. To skip the file altogether, put the
CDN link in the layout.
3 Link it #
Create app/Views/layouts/main.php:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= esc($title ?? 'My site') ?></title>
<?= link_tag('css/cirth.min.css') ?>
</head>
<body>
<main class="container">
<?= $this->renderSection('content') ?>
</main>
</body>
</html>
link_tag() comes with the HTML helper and builds the address from
app.baseURL, so that has to be where the app is served (step 5). A plain
<link rel="stylesheet" href="/css/cirth.min.css"> works as well. Link a
stylesheet of your own after Cirth's to override --cirth-* properties.
4 Write a view #
app/Views/subscribe.php extends the layout:
<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>
<article>
<header><h1>Hello, CodeIgniter</h1></header>
<?= form_open('subscribe') ?>
<label>
Email
<input type="email" name="email" required>
</label>
<button type="submit">Subscribe</button>
<?= form_close() ?>
</article>
<section data-theme="dark">
<article>
<p>Dark, whatever the system scheme is.</p>
</article>
</section>
<?= $this->endSection() ?>
The controller loads the HTML and form helpers and renders it, in
app/Controllers/Home.php:
<?php
namespace App\Controllers;
class Home extends BaseController
{
protected $helpers = ['html', 'form'];
public function index(): string
{
return view('subscribe', ['title' => 'Subscribe']);
}
}
5 Run it in production mode #
Copy the starter's env file to .env and set:
CI_ENVIRONMENT = production
app.baseURL = 'http://localhost:8080/'
Then install without the development packages and start the server:
composer install --no-dev --optimize-autoloader
php spark serve
php spark serve is for trying the app on your machine. In production,
point the web server's document root at public/ and give the stylesheet a
long cache lifetime, with the version in its name or query string.
6 Check it #
Open http://localhost:8080 with the system in light mode, then in dark
mode. The page follows the system, and the section with
data-theme="dark" stays dark both times. If the page has no styles at
all, app.baseURL points somewhere else: the link in the page source says
where.
Customization covers the --cirth-* properties; set
yours in a stylesheet linked after Cirth. Package and builds lists the classless,
scoped and print entry points. Return to Framework guides
for another stack.
CodeIgniter® is a registered trademark of the CodeIgniter Foundation. The CodeIgniter mark is owned and may be registered by the CodeIgniter Foundation. Cirth is an independent CSS framework and has not been authorized, sponsored, or otherwise approved by the CodeIgniter Foundation.