PHP Classes

Div PHP Ajax Mapping: Call PHP classes and functions using AJAX requests

Recommend this page to a friend!
  Info   View files Example   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-17 (2 months ago) RSS 2.0 feedStarStarStar 52%Total: 596 This week: 2All time: 5,218 This week: 96Up
Version License PHP version Categories
div-ajax-mapping 1.2GNU General Publi...5.4PHP 5, Web services, AJAX
Collaborate with this project 

Author

Description

This package can be used to call PHP classes and functions using AJAX requests.

It can register classes or global functions that will handle the responses to specified AJAX requests.

The server class then can handle the requests and invoke the registered methods.

It can also register requests for specific data values that may be returned as responses to AJAX requests without having to register a specific function for returning that data.

Innovation Award
PHP Programming Innovation award nominee
January 2015
Number 6
Many applications need to implement APIs that will be used to respond to AJAX requests performing some action.

A very common solution to implement this kind of API is to register some functions or classes that will generate the responses to the API calls.

However, in some cases the response for some types of requests is to return data already stored in variables or some other type of registered.

This class provides a simpler solution to return registered data without having to register a specific function.

Manuel Lemos
Picture of Rafa Rodriguez
  Performance   Level  
Name: Rafa Rodriguez <contact>
Classes: 6 packages by
Country: Suriname Suriname
Age: 37
All time rank: 17451 in Suriname Suriname
Week rank: 106 Up1 in Suriname Suriname Equal
Innovation award
Innovation award
Nominee: 3x

Example

<?php

/**
 * Div PHP Ajax Mapping
 * Mapping PHP data, functions and methods in JavaScript
 *
 * Example PHP script
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program as the file LICENSE.txt; if not, please see
 * http://www.gnu.org/licenses/gpl.txt.
 *
 * @author Rafa Rodriguez <rafageist@hotmail.com>
 * @link https://divengine.github.io/
 * @version 1.0
 */

session_start();

include
"../divAjaxMapping.php";

// A function
function getServerTime()
{
    return
date("y-m-d h:i:s");
}

// A class with static method
class Encryption
{

    public static function
getMd5($v)
    {
        return
md5($v);
    }

    public function
getSha1($v)
    {
        return
sha1($v);
    }
}

//
class MyAjaxServer extends divAjaxMapping
{

    public function
__construct($name)
    {
       
// Functions
       
$this->addMethod("getServerTime", false, false, array(), "Return the date and time of the server");

       
// Methods
       
$this->addMethod("getClientIP");
       
$this->addMethod("getPrivateData", false, true);
       
$this->addMethod("getProducts", false, true);

       
// Data
       
$this->addData("Date", date("D M-d \of Y"));
       
$this->addData("Server Description", "This is an example divAjaxMapping");

       
parent::__construct($name);
    }

    public function
getClientIP()
    {
        return
self::getClientIPAddress();
    }

    public function
getPrivateData()
    {
        return
"The number of your strong box is 53323";
    }

    public function
getProducts()
    {
        return array(
            array(
               
"Name" => "Chai",
               
"QuantityPerUnit" => "10 boxes x 20 bags",
               
"UnitPrice" => 18
           
),
            array(
               
"Name" => "Chang",
               
"QuantityPerUnit" => "24 - 12 oz bottles",
               
"UnitPrice" => 19
           
)
        );
    }
}

// Server instance

$server = new MyAjaxServer("This is an example of divAjaxMapping server");
$server->addClass('Encryption');
$server->go();


Details

PHP Hot Mapping Hot Mapping of PHP data, functions and methods in JavaScript phpHotMap is an open source library for JavaScript and PHP, that allow mapping the PHP functions, static methods of classes and arbitrary data on the spot of the instance a JavaScript class. With this class you can call a functions and methods via AJAX. For example: -------------------------------------------- In the server: -------------------------------------------- <?php // Include the library include "phpHotMap.php"; include "phpHotMapServer.php"; // The program // Note: the programa can be located in an external file function sum($x, $y){ return $x + $y; } class Enterprise{ public function getEmployees(){ return array( array("name" => "Thomas Hardy", "salary" => 1500), array("name" => "Christina Berglund", "salary" => 1200) ); } } // Server instance ... $server = new phpHotMaServer(); // ... Add methods ... $server->addMethod("sum", "x,y"); $server->addMethod("Enterprise::getEmployees", "x,y"); // ... and go! $server->go(); ?> -------------------------------------------- In the client: -------------------------------------------- <script type = "text/javascript" src="phpHotMap.js"></script> <script type = "text/javascript"> var client = new phpHotMapClient("server.php"); var sum = client.sum(20, 10); var employees = client.Enterprise.getEmployees(); var firstEmployeeName = employees[0]['name']; </script>

  Files folder image Files  
File Role Description
Files folder imageexample (4 files, 1 directory)
Files folder imagesrc (1 file)
Accessible without login Plain text file .gitignore Data new
Accessible without login Plain text file ajaxmap.js Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Data Auxiliary data
Accessible without login Plain text file LICENSE.txt Lic. first commit
Accessible without login Plain text file phpHotMap.js Data first commit
Plain text file phpHotMap.php Class first commit
Plain text file phpHotMapServer.php Class first commit
Plain text file README.md Class Class source
Accessible without login Plain text file README.txt Doc. first commit

  Files folder image Files  /  example  
File Role Description
Files folder imageassets (3 files)
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login Plain text file server.php Example first commit
  Accessible without login Plain text file start.bat Data Auxiliary data
  Accessible without login Plain text file start.sh Data Auxiliary data

  Files folder image Files  /  example  /  assets  
File Role Description
  Accessible without login Plain text file client.js Data Auxiliary data
  Accessible without login Plain text file divAjaxMapping.js Data Auxiliary data
  Accessible without login Plain text file style.css Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
  Plain text file ajaxmap.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 72%
Total:596
This week:2
All time:5,218
This week:96Up
 User Ratings  
 
 All time
Utility:66%StarStarStarStar
Consistency:58%StarStarStar
Documentation:66%StarStarStarStar
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:52%StarStarStar
Rank:2392