PHPackages                             mercator/wn-dynamicajax-plugin - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mercator/wn-dynamicajax-plugin

ActiveWinter-plugin[Utility &amp; Helpers](/categories/utility)

mercator/wn-dynamicajax-plugin
==============================

AJAX Dispatcher Plugin for Winter CMS Blocks.

0551PHP

Since Jun 4Pushed 4w agoCompare

[ Source](https://github.com/helmutkaufmann/wn-dynamicajax-plugin)[ Packagist](https://packagist.org/packages/mercator/wn-dynamicajax-plugin)[ RSS](/packages/mercator-wn-dynamicajax-plugin/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

AJAX Dispatcher — Mercator plugin for Winter CMS
================================================

[](#ajax-dispatcher--mercator-plugin-for-winter-cms)

A utility component that lets you call PHP functions and class methods from block markup via AJAX, without writing a full Winter CMS component. A single `ajaxDispatcher` component routes all theme-level AJAX requests to the right handler.

[![MIT License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

---

Installation &amp; Setup
------------------------

[](#installation--setup)

### 1. Plugin

[](#1-plugin)

Place the plugin files in:

```
plugins/mercator/dynamicajax

```

Then run:

```
php artisan winter:up
```

### 2. Frontend dependencies

[](#2-frontend-dependencies)

Include jQuery and the Winter CMS AJAX framework in your layout, before ``:

```

{% framework extras %}
```

### 3. Attach the component

[](#3-attach-the-component)

Add `ajaxDispatcher` to any page or layout where you want to use it:

```
[ajaxDispatcher]
```

---

How It Works
------------

[](#how-it-works)

### The handler string

[](#the-handler-string)

Pass a `handler` key via `data-request-data` to tell the dispatcher what to call. It looks for the PHP file in:

1. `themes/your-theme/blocks/.php`
2. `plugins/mercator/blocks/blocks/.php`

**Procedural function:**

```
handler: 'filename::functionName'

```

**Class method:**

```
handler: 'filename::Namespace\ClassName::methodName'

```

### Automatic parameter injection

[](#automatic-parameter-injection)

The dispatcher matches POST keys and `data-request-data` values to your PHP function's parameter names. No manual `post()` calls needed.

### Secure parameters with `parCrypt`

[](#secure-parameters-with-parcrypt)

Prefix any parameter with `encrypted_` and the dispatcher will automatically decrypt it before passing it to your handler. Use the `parCrypt` Twig function or filter to encrypt values in your markup:

```
{{-- as a function --}}
data-request-data="encrypted_recordId: '{{ parCrypt(123) }}'"

{{-- as a filter --}}
data-request-data="encrypted_recordId: '{{ 123 | parCrypt }}'"
```

---

Example
-------

[](#example)

### PHP handlers

[](#php-handlers)

Place these in `themes/your-theme/blocks/`.

**`greeterClass.php`** (class method):

```
