HTMX entegrasyonunu PHP projelerine dahil etmeyi kolaylaştıran hafif bir PHP yardımcı aracı.
Bu yardımcı sınıf, HTMX'e özgü başlıklar ve sunucu tarafı mantığı için temiz, ifade gücü yüksek fonksiyonlar sağlar — JavaScript yazmadan modern, etkileşimli web uygulamaları oluşturmak için idealdir.
🧪 Proje deposu: github.com/makalin/htmxphp
✅ HTMX isteklerini algıla
✅ İstemci tarafında olay tetikleme
✅ Yönlendirmeler, URL push/değiştirme
✅ JSON, HTML, içeriksiz (no-content) yanıtlar
✅ DOM değiştirme yardımcıları
✅ İstemci tarafı gezinme ve yenileme
✅ Basit fonksiyon tabanlı API
wget https://raw.githubusercontent.com/makalin/htmxphp/main/htmx.phpveya
git clone https://github.com/makalin/htmxphp.gitDaha sonra PHP dosyanıza dahil edin:
require_once 'htmx.php';is_htmx_request(): bool
is_htmx_boosted(): bool
get_htmx_trigger(): ?stringhtmx_trigger(string $eventName, array $data = [])
htmx_trigger_multiple(array $events)
htmx_push_url(string $url)
htmx_replace_url(string $url)
htmx_redirect(string $url)
htmx_location(string $url, string $target = "body", string $swap = "innerHTML")
htmx_refresh()
htmx_header(string $key, string $value)
htmx_status(int $code)htmx_html(string $html)
htmx_json(array $data)
htmx_nocontent()
htmx_replace(string $html)
htmx_raw(string $data)require_once 'htmx.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$msg = trim($_POST['message'] ?? '');
if ($msg) {
file_put_contents("log.txt", $msg . PHP_EOL, FILE_APPEND);
htmx_trigger('messageReceived', ['text' => $msg]);
htmx_nocontent();
} else {
htmx_status(400);
htmx_html("<div class='error'>Mesaj gereklidir.</div>");
}
}- Modern form gönderimleri
- Gerçek zamanlı içerik güncellemeleri
- Panolar & etkinlik akışları
- JavaScript framework’leri olmadan etkileşimli arayüzler
- PHP 7.2+
- HTMX frontend kütüphanesi
MIT Lisansı © 2025 Mehmet Turgay Akalın
Eğer bu proje işinize yaradıysa, GitHub'da repoya yıldız vererek destek olabilirsiniz:
👉 https://github.com/makalin/htmxphp