PHP code example of putyourlightson / datastar-php
1. Go to this page and download the library: Download putyourlightson/datastar-php library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
putyourlightson / datastar-php example snippets
use putyourlightson\datastar\events\FragmentEvent;
use putyourlightson\datastar\events\SignalEvent;
use putyourlightson\datastar\events\DeleteEvent;
use putyourlightson\datastar\events\RedirectEvent;
use putyourlightson\datastar\events\ConsoleEvent;
$event = new FragmentEvent();
$event->content = '<div id="primary">New content</div>';
// Optional
$event->id = 1;
$event->selector = '#secondary';
$event->merge = 'morph';
$event->settle = 100;
$event->vt = 'false';
$event = new SignalEvent();
$event->store = '{foo: "bar"}';
// Optional
$event->id = 1;
$event->onlyIfMissing = 'true';
$event = new DeleteEvent();
$event->selector = '#primary';
// Optional
$event->id = 1;
$event = new RedirectEvent();
$event->content = '/new-url';
// Optional
$event->id = 1;
$event = new ConsoleEvent();
$event->content = 'Hello world';
// Optional
$event->id = 1;
$event->mode = 'error';
// Returns the output of a Datastar event.
$output = $event->getOutput();
use putyourlightson\datastar\DatastarResponse;
$response = new DatastarResponse();
// Sends Datastar events to the browser.
$response->sendEvent($event1);
$response->sendEvent($event2);
$response->sendEvent($event3);
// Ends the response and closes the connection.
$response->end();
shell
composer