https://github.com/dconco/phpspa
A lightweight, component-based PHP library for building Single Page Applications (SPAs) without relying on heavy frontend frameworks.
https://github.com/dconco/phpspa
component-library javascript js jsx php php-spa phpslides spa
Last synced: 3 days ago
JSON representation
A lightweight, component-based PHP library for building Single Page Applications (SPAs) without relying on heavy frontend frameworks.
- Host: GitHub
- URL: https://github.com/dconco/phpspa
- Owner: dconco
- License: mit
- Created: 2025-05-30T10:37:49.000Z (30 days ago)
- Default Branch: main
- Last Pushed: 2025-06-24T12:09:48.000Z (4 days ago)
- Last Synced: 2025-06-24T12:34:24.210Z (4 days ago)
- Topics: component-library, javascript, js, jsx, php, php-spa, phpslides, spa
- Language: PHP
- Homepage:
- Size: 919 KB
- Stars: 9
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ðĶ **phpSPA - Build Native PHP SPAs Without JavaScript Frameworks**
## ð **Name**
**phpSPA** lets you build fast, interactive single-page apps using **pure PHP** â with dynamic routing, component architecture, and no full-page reloads. No JavaScript frameworks required.


[](https://phpspa.readthedocs.io)
[](https://github.com/dconco/phpspa)
[](https://packagist.org/packages/dconco/phpspa)
[](https://packagist.org/packages/dconco/phpspa)---
## ðŊ **Goal**
To empower PHP developers to create **modern, dynamic web apps** with the elegance of frontend SPA frameworks â but fully in PHP.
* ðŦ No full-page reloads
* ⥠Instant component swapping
* ð§ą Clean, function-based components
* ð Real SPA behavior via History API
* ð§ Now with **State Management**!---
## ð§ą **Core Features**
* ð Dynamic content updates â feels like React
* ð§Đ Component-based PHP architecture
* ð URL routing (client + server synced)
* ð§ **Built-in State Management**
* âïļ Lifecycle support for loaders, metadata, etc.
* ðŠķ Minimal JS: one small file
* ð Graceful fallback (no JS? Still works)---
## âĻ Features
* â Fully PHP + HTML syntax
* â No template engines required
* â Dynamic GET & POST routing
* â Server-rendered SEO-ready output
* â Per-component and global loading indicators
* â Supports Composer or manual usage
* â **State system**: update UI reactively from JS---
## ð§ Concept
* **Layout** â The base HTML (with `__CONTENT__`)
* **Component** â A PHP function returning HTML
* **App** â Registers and runs components based on routes
* **State** â Simple mechanism to manage reactive variables across requests---
## ð§Đ State Management
You can create persistent state variables inside your components using:
```php
$counter = createState("counter", 0);
```Update state from the frontend:
```js
phpspa.setState("counter", newValue);
```This will automatically **re-render** the component on update.
---
## ðĶ Installation
### 1. Via Composer (Recommended)
```bash
composer require dconco/phpspa
```Include the autoloader:
```php
require 'vendor/autoload.php';
```### 2. Manual
Include the core files:
```php
require 'path/to/phpspa/core/App.php';
require 'path/to/phpspa/core/Component.php';
```---
### ð JS Engine (CDN)
```html
```
---
## ð **Getting Started (with Live Counter)**
```php
My Live App
__CONTENT__