117 lines
3.1 KiB
Markdown
117 lines
3.1 KiB
Markdown
# 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
|
|
|
|
1. **index.php** receives all requests and parses the URL
|
|
2. It determines which template to load from `PAGE_TEMPLATES` in config
|
|
3. The template file is loaded with `ob_start()` to buffer output
|
|
4. Templates can set variables like `$pageTitle`, `$pageDescription`, `$additionalHead`, etc.
|
|
5. The header is rendered (with access to template variables)
|
|
6. The buffered template content is output
|
|
7. The footer is rendered
|
|
|
|
## Configuration
|
|
|
|
Edit `assets/config.php` to customize:
|
|
|
|
- `SITE_NAME` - Your site name
|
|
- `SITE_URL` - Your site URL
|
|
- `PAGE_TEMPLATES` - Add/remove pages and their settings
|
|
|
|
## Adding New Pages
|
|
|
|
1. Add a new entry to `PAGE_TEMPLATES` in `assets/config.php`:
|
|
|
|
```php
|
|
'services' => [
|
|
'file' => 'services.php',
|
|
'title' => 'Services'
|
|
]
|
|
```
|
|
|
|
2. Create the template file in `templates/services.php`
|
|
3. 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
|
|
<?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):
|
|
|
|
```apache
|
|
RewriteEngine On
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
RewriteCond %{REQUEST_FILENAME} !-d
|
|
RewriteRule ^(.*)$ index.php/$1 [L]
|
|
```
|
|
|
|
### PHP Built-in Server
|
|
|
|
For development:
|
|
|
|
```bash
|
|
php -S localhost:8000
|
|
```
|
|
|
|
Then visit: `http://localhost:8000/index.php/about`
|
|
|
|
## License
|
|
|
|
Free to use for any purpose.
|