Download the PHP package amranich/ajax-router without Composer
On this page you can find all versions of the php package amranich/ajax-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amranich/ajax-router
More information about amranich/ajax-router
Files in amranich/ajax-router
Package ajax-router
Short Description Handle your AJAX requests efficiently
License MIT
Informations about the package ajax-router
Getting Started
You can copy/paste this code snippet for a quick start.
We're using Guzzle PSR-7 interface implementation here, but you can use any other library you like as long as it implements the same interface.
Usage Tips
Route to controller/class method
If you like to put the business logic in a separate class or in a controller, you can route your requests to them like this :
Or :
If the controller/class has some dependencies that must be passed within the constructor, you can still instantiate the controller on yourself :
Catch route actions exceptions
I want to catch exceptions that only occurs from my routes actions, and not those thrown by the library or somewhere else, how I can do that ?
Answer :
Get current route
You can access the current route object using the static method getCurrentRoute of the Route class.
Background
The idea of the library came to my mind a long time ago when I was mostly developing web applications using just plain PHP, some of these applications were performing a lot of AJAX requests into a single PHP file, that file can have a hundred lines of code that process these requests depending on a function/method name that sent along with the request, so I started to think of what I can do to improve the way that these requests are handled, and improve the code readability and maintainability.
🏆 Prize
This package wins the PHP Innovation Award (February 2022) Issued by phpclasses.org.
Certificate : https://amranich.dev/certs/phpclasses-february-2022-innovation-award.pdf
They support this project

All versions of ajax-router with dependencies
psr/http-message Version ^1.0
lazzard/psr7-response-sender Version ^1.0