Update README.md

This commit is contained in:
jasonhilder
2026-05-29 10:42:52 +02:00
parent fcd58a4afb
commit 3c232440c2
+117 -26
View File
@@ -4,11 +4,13 @@ A tiny PHP starter project for small websites and personal projects.
The goal is simple:
- Clone
- Change git remote
- Start building
* Clone
* Change git remote
* Start building
No framework.
No Composer.
No external dependencies.
No ORM.
No dependency injection.
No magic.
@@ -19,13 +21,28 @@ Just PHP.
## Features
- Simple config-based router
- Page and API endpoints
- SQLite support via PDO
- Shared partials
- Secure path traversal protection
- Helper functions
- Development server script
* Zero dependencies
* No Composer required
* Simple config-based router
* Page and API endpoints
* SQLite support via PDO
* Shared partials
* Secure path traversal protection
* Helper functions
* Development server script
---
## Requirements
* PHP 8.1+
* SQLite extension (optional)
Check installed extensions:
```bash
php -m
```
---
@@ -33,7 +50,6 @@ Just PHP.
```text
config/
├── app.php
├── database.php
└── routes.php
@@ -55,12 +71,17 @@ src/
storage/
└── database.sqlite
index.php
server.sh
```
---
## Running
Start the development server:
```bash
./server.sh
```
@@ -113,28 +134,90 @@ src/views/pages/
---
## Pages
## Adding A New Page
Example page:
### 1. Create the page
Create:
```text
src/views/pages/contact.php
```
Example:
```php
<?php
<?php partial('head', ['title' => 'Contact']); ?>
partial('head', [
'title' => 'Home',
]);
<h1>Contact</h1>
?>
<h1>Home</h1>
<p>Hello world.</p>
<p>Get in touch.</p>
<?php
partial('footer');
```
### 2. Add the route
Edit:
```php
config/routes.php
```
Add:
```php
'GET' => [
'/contact' => 'contact.php',
],
```
Visit:
```text
http://localhost:3333/contact
```
---
## Adding An API Endpoint
### 1. Create the endpoint
Create:
```text
src/api/contact.php
```
Example:
```php
<?php
declare(strict_types=1);
header('Content-Type: application/json');
echo json_encode(['success' => true]);
```
### 2. Add the route
```php
'GET' => [
'/api/contact' => 'api/contact.php',
],
```
Visit:
```text
http://localhost:8000/api/contact
```
---
## SQLite
@@ -150,9 +233,7 @@ Usage:
```php
$db = db();
$rows = $db->query(
'SELECT * FROM users'
)->fetchAll();
$rows = $db->query('SELECT * FROM users')->fetchAll();
```
---
@@ -171,6 +252,16 @@ partial()
---
## Philosophy
miniPHP intentionally avoids framework features.
If a feature can be implemented with plain PHP and a few lines of code, prefer that approach.
The goal is to remain small, understandable, and easy to clone for future projects.
---
## License
MIT
MIT