PHPackages                             zotenme/hyperf-ajax - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. zotenme/hyperf-ajax

ActiveLibrary[Templating &amp; Views](/categories/templating)

zotenme/hyperf-ajax
===================

Larajax-compatible HTML-over-the-wire AJAX helpers for Hyperf.

v1.0.3(1mo ago)068↓50%MITPHPPHP ^8.3

Since Jul 10Pushed 1mo agoCompare

[ Source](https://github.com/Zotenme/hyperf-ajax)[ Packagist](https://packagist.org/packages/zotenme/hyperf-ajax)[ RSS](/packages/zotenme-hyperf-ajax/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (4)Dependencies (11)Versions (5)Used By (0)

Hyperf Ajax
===========

[](#hyperf-ajax)

[![PHP Version](https://camo.githubusercontent.com/5c8ce4571ddf4b6b8ca847e0c4c079de98fc6460eb7eae9c81ca63319c21f546/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e332d626c75652e737667)](https://php.net/)[![Hyperf Version](https://camo.githubusercontent.com/77f167c25b07bf531eb404fd9859135155f910f92d65de7984c2aa39dd74b202/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6879706572662d253545332e322d677265656e2e737667)](https://hyperf.io/)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE.md)![Tests](https://camo.githubusercontent.com/3ab4882a1b7d64e5eb5168ad0b0b9cdfd53f59f114ee5f727958504214a5789c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d70617373696e672d627269676874677265656e2e737667)![PHPStan](https://camo.githubusercontent.com/6e33b77b51a771e6655e2b9229dca1682109fdbaae399ff6b2d6d7a4d5e35db7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d6c6576656c253230382d627269676874677265656e2e737667)

Hyperf Ajax is a Hyperf backend package compatible with the Larajax browser protocol. It lets a normal Hyperf page controller answer HTML-driven AJAX handlers such as `data-request="onSave"` without creating a separate JSON API route for every UI interaction.

This repository currently contains the first MVP implementation:

- Hyperf package skeleton with `ConfigProvider`;
- Larajax-compatible `__ajax` response envelope;
- DOM patch, partial, redirect, reload, flash, browser event and asset operations;
- explicit controller trait and base controller for `onXxx` handler dispatch;
- component container with `component::onHandler` support;
- validation/error mapper;
- publishable frontend assets copied from Larajax dist.

Installation
------------

[](#installation)

For local development:

```
composer require zotenme/hyperf-ajax
```

Publish the frontend assets in a Hyperf application using Hyperf's vendor publish flow. The package exposes `resources/dist` as `public/vendor/hyperfajax`.

Frontend
--------

[](#frontend)

Use either the existing npm package:

```
npm install larajax
```

```
import { jax } from 'larajax';

window.jax = jax;
jax.start();
```

Or serve the published bundle:

```

```

`framework-bundle.min.js` starts the framework automatically. Do not call `window.jax.start()` with this bundle.

The published bundles are redistributed from Larajax 2.2.3. See [Third-Party Notices](THIRD_PARTY_NOTICES.md) for the upstream copyright and MIT license notice.

Controller Usage
----------------

[](#controller-usage)

The recommended low-friction entry point is `HyperfAjaxController` with `ajaxPage()`. The method renders a normal page for regular requests and dispatches `onXxx` handlers for AJAX requests.

`ajaxPage()` is the intentional public integration boundary. Call it explicitly from each page action that supports AJAX. The package does not install automatic middleware, attributes or AOP interception: Hyperf controllers may be long-lived, and keeping the concrete controller instance and request lifecycle explicit avoids hidden coroutine state. The render callback is lazy and is never called for an AJAX request.

```
