An open API service indexing awesome lists of open source software.

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.

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.

![License](https://img.shields.io/badge/license-MIT-blue.svg)
![JS Version](https://img.shields.io/badge/version-1.1.2-green.svg)
[![Documentation](https://readthedocs.org/projects/phpspa/badge/?version=latest)](https://phpspa.readthedocs.io)
[![GitHub stars](https://img.shields.io/github/stars/dconco/phpspa?style=social)](https://github.com/dconco/phpspa)
[![PHP Version](https://img.shields.io/packagist/v/dconco/phpspa)](https://packagist.org/packages/dconco/phpspa)
[![Total Downloads](https://img.shields.io/packagist/dt/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__