5d0874eab1904cfb0c7974858cb92ab7720b6ae3
Simple Framework
A lightweight PHP framework with clean routing and template management.
Features
- Simple Routing: Clean URLs through
index.php(e.g.,/index.php/about) - Template System: Organized template files with reusable header/footer
- Output Buffering: Templates can set variables that are used in header/footer
- Configuration Management: Centralized constants in
assets/config.php - No Dependencies: Pure PHP, no external libraries required
Structure
/
âââ assets/
â âââ config.php # Site configuration and constants
â âââ css/
â â âââ style.css # Main stylesheet
â âââ js/
â âââ main.js # Main JavaScript
âââ includes/
â âââ header.php # Site header
â âââ footer.php # Site footer
âââ templates/
â âââ home.php # Home page template
â âââ about.php # About page template
â âââ contact.php # Contact page template
âââ index.php # Bootstrap/Router
âââ README.md
How It Works
- index.php receives all requests and parses the URL
- It determines which template to load from
PAGE_TEMPLATESin config - The template file is loaded with
ob_start()to buffer output - Templates can set variables like
$pageTitle,$pageDescription,$additionalHead, etc. - The header is rendered (with access to template variables)
- The buffered template content is output
- The footer is rendered
Configuration
Edit assets/config.php to customize:
SITE_NAME- Your site nameSITE_URL- Your site URLPAGE_TEMPLATES- Add/remove pages and their settings
Adding New Pages
- Add a new entry to
PAGE_TEMPLATESinassets/config.php:
'services' => [
'file' => 'services.php',
'title' => 'Services'
]
- Create the template file in
templates/services.php - The page will automatically appear in the navigation
Template Variables
Templates can set these variables to customize the output:
$pageTitle- Page title (appears in<title>tag)$pageDescription- Meta description$bodyClass- CSS class for<body>tag$additionalHead- Extra HTML for<head>section$footerExtra- Extra content in the footer
Example Template
<?php
$pageTitle = 'My Page';
$pageDescription = 'This is my page description';
$bodyClass = 'my-custom-class';
?>
<section>
<h1>My Page Content</h1>
<p>This content will be wrapped by header and footer.</p>
</section>
Server Configuration
Apache
Enable mod_rewrite and use this .htaccess for cleaner URLs (optional):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
PHP Built-in Server
For development:
php -S localhost:8000
Then visit: http://localhost:8000/index.php/about
License
Free to use for any purpose.
Description
Languages
PHP
41%
CSS
30.1%
JavaScript
12.2%
Hack
11.8%
Dockerfile
4.9%