Download the PHP package giantbits/yii2-htmx without Composer

On this page you can find all versions of the php package giantbits/yii2-htmx. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-htmx

yii2-htmx

HTMX-powered component framework for Yii2. Build interactive UIs with server-rendered components — no JavaScript framework, no build tools.

Each component is a self-contained class + template pair that automatically gets an HTMX endpoint. User interactions trigger server-side actions, and HTMX swaps the fresh HTML into the DOM. The developer experience is similar to React/Vue but everything runs server-side.

Installation

The package auto-bootstraps via Yii2's extension system — no manual configuration needed. It registers:

For Twig template support (recommended):

And configure the renderer in your app config:

Quick Example

A component is two files side by side:

Counter.php

Counter.view.twig

Use it anywhere:

Or in Twig:

Click the buttons — the counter updates without a page reload. No JavaScript written.

How It Works

Every component instance gets a unique signed URL. The HMAC signature (using your app's cookieValidationKey) prevents tampering with class names, props, or actions.

Creating Components

The Component Class

Extend HtmxComponent and override what you need:

The Template

Templates receive the component instance as component. Use the HTMX helpers to wire up interactions:

Twig (.view.twig):

PHP (.view.php) — also supported:

The base class prefers .view.twig and falls back to .view.php.

Props

Props are passed from parent to child and serialized into the endpoint token. Use them as lightweight identifiers — not full data objects.

The component resolves the actual data in resolveState():

This keeps tokens small and data always fresh.

HTMX Helpers

These generate the full set of HTMX attributes in one call — no manual URL or target wiring:

Helper Generated Attributes
component.hxGet('render') hx-get="..." hx-target="#id" hx-swap="outerHTML"
component.hxPost('action') hx-post="..." hx-target="#id" hx-swap="outerHTML"
component.hxPut('action') hx-put="..." ...
component.hxPatch('action') hx-patch="..." ...
component.hxDelete('action') hx-delete="..." ...
component.hxTriggerListen('event') hx-get="..." hx-trigger="event from:body" ...

Override or add attributes with the second argument:

In Twig, always pipe through | raw since the output is pre-escaped HTML attributes.

Cross-Component Communication

Components communicate through HTMX events — decoupled, like a pub/sub system.

Publisher — emits an event after an action:

Subscriber — listens and auto-refreshes:

When the publisher's action completes, the HX-Trigger response header fires jobListChanged, and any element with hx-trigger="jobListChanged from:body" automatically re-fetches itself.

You can also emit multiple events:

Action Utilities

Use these inside action*() methods:

Component Properties

Property Type Default Description
props array [] Data passed from parent, serialized into the endpoint token
swapStrategy string 'outerHTML' Default HTMX swap strategy
componentId ?string auto DOM ID. Auto-generated from class name + props hash
tag string 'div' Wrapper element tag
wrapperOptions array [] Extra HTML attributes for wrapper

Configuration

Set these in Yii::$app->params:

PJAX Migration

If you're migrating from Yii2's built-in Pjax, the mapping is straightforward:

Pjax Pattern HTMX Component Equivalent
Pjax::begin() ... Pjax::end() MyComponent::widget()
$.pjax({url, container}) component.hxGet('render')
$.pjax.reload({container}) component.hxTriggerListen('event')
PJAX container ID component.componentId (auto-generated)
pjax:complete event HX-Trigger response header + hx-trigger attribute

Key advantages over Pjax:

Security

Component endpoint URLs contain HMAC-signed tokens. The token encodes the class name, props, and action, signed with your app's cookieValidationKey. This prevents:

Only actions listed in the actions() method can be invoked. The ComponentController verifies signatures before processing any request.

Requirements


All versions of yii2-htmx with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
yiisoft/yii2 Version ~2.0.45
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package giantbits/yii2-htmx contains the following files

Loading the files please wait ...