SPA tool for PHP developers

It’s simple tool to build a Single Page Application based on PHP with minimal JS require

Why it is a good one?

  1. The tool has no dependency to specific framework.
    It could be used for any framework on PHP, including Wordpress, Laravel, Symfony, Yii etc.
  2. It’s easy to implement
    There is clear installation tutorial
  3. Layout handler is optional
    You can use native PHP includes, like in WP. Also you can use a layout handler, like twig or blade. That’s up on you.
  4. There is technical documentation for all features
    No needs to investigate source code to understand, how it works

Is there any other kind tool?

Yes, sure. There are others similar frameworks/tools on the market. But the most good analogs have a specific.

Part of analogs were developed for single framework, like Livewire for Laravel, Sprig for Craft CMS or Turbolinks for Ruby on Rails. The another ones require a lot skills and time for implementation, like Inertiajs.

PHP-developer oriented tool

It's unnecessary to spend much time to adapt tool or to JS development for a project

The simple installation and quick start for any PHP project, that’s the main reason, why the Sparky was created.

Simple syntax

The syntax is very similar to Livewire. Please check the next screenshots

Component implementation

The next code will display current time and a button to refresh the data.
Also it will refresh by itself each minute


// Clock Component

namespace App\SparkyComponent;

use SparkySpa\Component;

class ClockComponent extends Component
{
public $time_now;

#region Actions

/**
* @inheritDoc
*/
protected function render()
{
$this->time_now = date('H:i:s');

return $this->view('spa/clock');
}

#endregion
}


// Input the Component to a page template

echo sparky(ClockComponent::getName());


// Layout `spa/clock` implementation for the Component

<p spa:emit.1m="refresh()">
It is <?php echo $time_now ?> now
</p>
<button spa:click="refresh()" type="button">Refresh</button>

            

Bind Component property to a field


// Layout `spa/chat` implementation for the Component

@if ($history)
<ul>
@foreach ($history as $msg)

    <li> {{ $msg }} </li>

@endforeach
</ul>
@endif

<input spa:bind name="message" placeholder="Put your message here" type="text">
<button spa:click="sendMessage( {{ $flag }} )" type="button">Send</button> 

// Chat Component

namespace App\SparkyComponent;

use SparkySpa\Component;

class Chat extends Component
{
public int $chat_id;
public ?string $message = null

private bool $flag = true;

#region Actions

/**
*
*/
protected function mount()
{
// A code to define $this->chat_id
}

/**
* @inheritDoc
*/
protected function render()
{
return $this->view('spa/chat', [
    'history' => $this->getHistory(),
    'flag' => $this->flag,
]);
}

/**
*
*/
public function sendMessage($flag)
{
// A code to save property $this->message into a DB

$this->flag = !filter_var($flag, FILTER_VALIDATE_BOOLEAN);
$this->message = null;
}

#endregion

#region Getters

/**
* @return  string[];
*/
private function getHistory()
{
$history = [];

// A code to set a history to the var $history

return $history;
}

#endregion
}

            
Sparky SPA logo

Check the Documentation

© 2022 | Developed by Pavlo Matsura in Ukraine 🇺🇦
Theme designed by Xiaoying Riley
Did you get an issue?
Is it useful for you? Please ❤️ Donate