Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/everlutionsk/ajaxcom

AjaxCom - control front-end from PHP
https://github.com/everlutionsk/ajaxcom

Last synced: about 1 month ago
JSON representation

AjaxCom - control front-end from PHP

Awesome Lists containing this project

README

        

[![Build Status](https://scrutinizer-ci.com/g/everlutionsk/AjaxCom/badges/build.png?b=master)](https://scrutinizer-ci.com/g/everlutionsk/AjaxCom/build-status/master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/everlutionsk/AjaxCom/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/everlutionsk/AjaxCom/?branch=master)

# AjaxCom
AjaxCom is a PHP library that allows developers to write their ajax code in PHP with minimal javascript.

### Demo
http://ajaxcom.everlution.sk/

## Features
- Append html to elements
- Prepend html to elements
- Replace elements with new html
- Set html of elements
- Set value of elements
- Display flash messages
- Display modals
- Change URL
- Call functions

## Requirements
- PHP >= 5.3.3
- jQuery >= 1.7.x

## Installation
Via composer:

``` json
{
"require": {
"dm/ajaxcom": "dev-master"
}
}
```

## Usage
### Javascript
Include the javascript library located at `src/DM/AjaxCom/Resources/public/js/ajaxcom.js`

Intercept all click events on anchors and submit events on forms:
``` javascript
$(document).ajaxcom();
```

Or just intercept those which have `data-ajaxcom`
``` javascript
$(document).ajaxcom('[data-ajaxcom]');
```

### PHP
``` php
use DM\AjaxCom\Handler;

if (isset($_SERVER['X-AjaxCom'])) {
// Render page using AjaxCom library
$handler = new Handler();
// Change URL to /newurl
$handler->changeUrl('/newurl');
// Append some html to an element
$handler->container('#table')
->append('This is a new row');
// Replace element with some new html
$handler->container('#something')
->replaceWith('Some text');
// Display modal
$handler->modal(
'

'
);

// NOTE: It is important to call callback() AFTER container() or modal()
// when you are manipulating the rendered DOM inside the callback;
// otherwise the callback will be called before elements of DOM are loaded

// Call funcname()
$handler->callback('funcname');
// Call namespace.funcname()
$handler->callback('namespace.funcname');
// You can also specify parameters which will be passed as object to the funcion
$handler->callback('namespace.funcname', ['this' => 'will', 'be' => 'passed', 'as' => 'an object', 'to' => 'the function']);

header('Content-type: application/json');
echo json_encode($handler->respond());
} else {
// Render page normally
}
```