Update README.md
This commit is contained in:
@@ -4,11 +4,13 @@ A tiny PHP starter project for small websites and personal projects.
|
|||||||
|
|
||||||
The goal is simple:
|
The goal is simple:
|
||||||
|
|
||||||
- Clone
|
* Clone
|
||||||
- Change git remote
|
* Change git remote
|
||||||
- Start building
|
* Start building
|
||||||
|
|
||||||
No framework.
|
No framework.
|
||||||
|
No Composer.
|
||||||
|
No external dependencies.
|
||||||
No ORM.
|
No ORM.
|
||||||
No dependency injection.
|
No dependency injection.
|
||||||
No magic.
|
No magic.
|
||||||
@@ -19,13 +21,28 @@ Just PHP.
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Simple config-based router
|
* Zero dependencies
|
||||||
- Page and API endpoints
|
* No Composer required
|
||||||
- SQLite support via PDO
|
* Simple config-based router
|
||||||
- Shared partials
|
* Page and API endpoints
|
||||||
- Secure path traversal protection
|
* SQLite support via PDO
|
||||||
- Helper functions
|
* Shared partials
|
||||||
- Development server script
|
* 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
|
```text
|
||||||
config/
|
config/
|
||||||
├── app.php
|
|
||||||
├── database.php
|
├── database.php
|
||||||
└── routes.php
|
└── routes.php
|
||||||
|
|
||||||
@@ -55,12 +71,17 @@ src/
|
|||||||
|
|
||||||
storage/
|
storage/
|
||||||
└── database.sqlite
|
└── database.sqlite
|
||||||
|
|
||||||
|
index.php
|
||||||
|
server.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
|
Start the development server:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./server.sh
|
./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
|
<?php partial('head', ['title' => 'Contact']); ?>
|
||||||
|
|
||||||
partial('head', [
|
<h1>Contact</h1>
|
||||||
'title' => 'Home',
|
|
||||||
]);
|
|
||||||
|
|
||||||
?>
|
<p>Get in touch.</p>
|
||||||
|
|
||||||
<h1>Home</h1>
|
|
||||||
|
|
||||||
<p>Hello world.</p>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
partial('footer');
|
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
|
## SQLite
|
||||||
@@ -150,9 +233,7 @@ Usage:
|
|||||||
```php
|
```php
|
||||||
$db = db();
|
$db = db();
|
||||||
|
|
||||||
$rows = $db->query(
|
$rows = $db->query('SELECT * FROM users')->fetchAll();
|
||||||
'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
|
## License
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
Reference in New Issue
Block a user