adair-creative/js-actions

There is no license information available for the latest version (dev-master) of this package.

Allows for easy use of server-side actions from Javascript

dev-master 2019-05-20 19:17 UTC

This package is auto-updated.

Last update: 2024-04-21 19:56:21 UTC


README

A tool that allows for easy actions to easily be called from the client Javascript, featuring typed arguments, automatic method execution, DataObject getting by IDs & default values!

Note: This is just a beta so it may be unstable and there will be more to come

composer require adair-creative\js-actions

Usage

PHP

class MyPage extends PageController {
	public function action_searchProducts(string $name, int $maxResults = 10, HTTPRequest $request) {
		return json_encode(Product::get()->filter("Name", $name)->limit($maxResults));
	}
}

Javascript

if ($(document.body).hasClass("MyPage")) {
	Controller.searchProducts($(".search").val()).then(result => {
		// ...
	});
}

Config

AdairCreative\JsActionsController:
    - js_namespace: "MyController"
    - action_prefix: "MyAction"