CakePHP InteractInteractive pages. Written in PHP.
Keep your CakePHP templates and application logic. Update the part of the page that changed.
Keep your CakePHP templates and application logic. Update the part of the page that changed.
An island owns a region of your page. A button calls its PHP action, and Interact updates that region with freshly rendered HTML.
These three files work together after installation:
<?php
declare(strict_types=1);
namespace App\Island;
use Interact\Attribute\Action;
use Interact\Attribute\State;
use Interact\Island;
/**
* Keeps a count for one region and changes it through a server action.
*
* Save as src/Island/CounterIsland.php.
*/
class CounterIsland extends Island
{
#[State]
public int $count = 0;
/**
* Increase this island's count when its button is pressed.
*/
#[Action]
public function increment(): void
{
$this->count++;
}
}<?php
declare(strict_types=1);
/**
* templates/island/counter.php
*
* @var int $count
*/
?>
<p aria-live="polite">Count: <?= (string)$count ?></p>
<button
type="button"
@click="$server.call('increment')"
:disabled="$server.busy"
>
Add one
</button>
<p role="alert" x-text="$server.error ? $server.error.message : ''"></p><?php
declare(strict_types=1);
/**
* templates/Articles/index.php
*
* @var \Cake\View\View $this
*/
?>
<h1>Articles</h1>
<?= $this->Interact->render('Counter') ?>Use the same approach for live search, editable forms, and independent nested editors. CakePHP continues to own queries, validation, authorization, and saving.
See HTML directives and $server for syntax and options, or Examples for complete implementations.
Interact is a development preview for PHP 8.5 and CakePHP 6 development builds. Install dev-main from Packagist; there is no stable release yet. Start with installation, or run the included demo to try the interactions before integrating it into an application.