@dconco/phpspa
v2.0.9
Published
Client-side JavaScript library for PhpSPA - Component-based PHP framework with SPA-like navigation
Readme
Component-Based PHP Library for Modern Web Applications
Build dynamic, interactive web applications using reusable PHP components with state management and SPA-like behavior — no JavaScript frameworks required.
✨ Key Features
🚀 Getting Started
🎯 Ready to Jump In? Start with our Template!
Get up and running in 30 seconds with a complete PhpSPA example
Step 1: Clone the Template
composer create-project phpspa/phpspa my-phpspa-app
cd my-phpspa-appStep 3: Start Development Server
composer start🎉 That's it! Your PhpSPA application is now running locally.
Open your browser and start building amazing components!
🚀 Quick Start
If you want to set up PhpSPA manually, maybe in an existing project, follow these steps:
Install
composer require dconco/phpspaNamespace
First you need to include the namespace at the beginning of your app.
<?php
use PhpSPA\App;
use PhpSPA\Component;
use function Component\useState;
require_once 'vendor/autoload.php';Create Component
function HomePage() {
$counter = useState("count", 0);
return <<<HTML
<h1>Counter: {$counter}</h1>
<button onclick="setState('count', {$counter} + 1)">+</button>
<Component.Link to="/about" children="About" />
HTML;
}Setup App
$app = new App(fn() => '<div id="app"></div>');
$app->attach((new Component('HomePage'))->route('/'));
$app->run();⚡ Native Compression (C++ FFI)
To enable the fastest HTML/CSS/JS compression, add this to your php.ini:
ffi.enable=true
extension=ffiThen add this line to your code:
use PhpSPA\Compression\Compressor;
$app->compression(Compressor::LEVEL_AGGRESSIVE, true)You’ll see X-PhpSPA-Compression-Engine: native in response headers when active.
🎨 What You Get
📚 Learn More
🔗 Complete Documentation — Full tutorials, examples and guides
👉 API References — Detailed API documentation for all PhpSPA features
📦 Packagist — Installation and versions
🤝 Contributing
We welcome contributions from the community! Whether you want to add new hooks, fix bugs, or improve documentation, your help is appreciated.
👉 Read our Contributing Guide to get started
✨ Crafted with Precision By
Dave Conco
Building modern web applications with the simplicity of PHP
⭐ If you find PhpSPA useful, please give it a star!
