1. Go to this page and download the library: Download abdullahozcan/liveigniter 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/ */
namespace App\LiveComponents;
use LiveIgniter\LiveComponent;
class Counter extends LiveComponent
{
public int $count = 0;
public string $message = 'Hello from LiveIgniter!';
public function increment(): void
{
$this->count++;
}
public function decrement(): void
{
$this->count--;
}
public function reset(): void
{
$this->count = 0;
}
}
<!-- Component with auto-generated x-data -->
<div id="<?= $componentId
// Emit an event
$this->emit('user.updated', $userId, $userData);
// Listen for events
$this->listen('user.updated', function($userId, $userData) {
// Handle the event
});
class MyComponent extends LiveComponent
{
public string $name = '';
public int $age = 0;
public array $items = [];
public bool $isActive = false;
public ?User $user = null;
}
namespace Config;
use LiveIgniter\Config\LiveIgniter as BaseLiveIgniter;
class LiveIgniter extends BaseLiveIgniter
{
public bool $debug = true;
public int $sessionLifetime = 3600;
public string $assetsUrl = '/liveigniter/assets/';
// ... other configuration options
}
class UserProfile extends LiveComponent
{
public User $user;
public string $name = '';
public string $email = '';
public function mount(User $user): void
{
$this->user = $user;
$this->name = $user->name;
$this->email = $user->email;
}
public function save(): void
{
$this->user->update([
'name' => $this->name,
'email' => $this->email
]);
session()->setFlashdata('success', 'Profile updated!');
}
public function cancel(): void
{
$this->name = $this->user->name;
$this->email = $this->user->email;
}
}
class ChatComponent extends LiveComponent
{
public array $messages = [];
public function mount(): void
{
$this->refreshMessages();
// Listen for new messages
$this->listen('message.sent', [$this, 'onMessageSent']);
}
public function sendMessage(string $message): void
{
// Save message
$messageModel = new MessageModel();
$messageModel->save([
'user_id' => auth()->id(),
'message' => $message
]);
// Emit to other components
$this->emit('message.sent', $message);
}
public function onMessageSent(): void
{
$this->refreshMessages();
}
private function refreshMessages(): void
{
$this->messages = (new MessageModel())->findAll();
}
}
public bool $debug = true;
bash
php spark liveigniter:install
bash
php spark liveigniter:publish
bash
# Install LiveIgniter (recommended for new projects)
php spark liveigniter:install
# Publish only assets
php spark liveigniter:publish --assets
# Publish only config files
php spark liveigniter:publish --config
# Publish example views
php spark liveigniter:publish --views
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.