PHPackages                             phery/phery - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. phery/phery

ActiveLibrary[File &amp; Storage](/categories/file-storage)

phery/phery
===========

XAJAX alternative, phery.js is a library in PHP that maps to all jQuery functions, DOM manipulation, meta arguments and serialization, seamless ajax integration, RESTful emulation, form submission and partial rendering views, plus its PSR-0 compatible

2.7.4(9y ago)13813.1k36[19 issues](https://github.com/pocesar/phery/issues)2MITPHPPHP &gt;=5.3.3

Since Sep 4Pushed 2y ago20 watchersCompare

[ Source](https://github.com/pocesar/phery)[ Packagist](https://packagist.org/packages/phery/phery)[ Docs](http://phery-php-ajax.net)[ RSS](/packages/phery-phery/feed)WikiDiscussions 3.0.0-alpha2 Synced 1mo ago

READMEChangelog (6)DependenciesVersions (37)Used By (2)

PHP + jQuery + AJAX + File upload
=================================

[](#php--jquery--ajax--file-upload)

Enter phery.js, the swiss army knife of jQuery and PHP
======================================================

[](#enter-pheryjs-the-swiss-army-knife-of-jquery-and-php)

Highlights
----------

[](#highlights)

- Subscribe on the client and publish on the server, and execute functions bound to elements fast and easy, within their own contexts.
- Declarative and unobstrusive HTML instead of imperative Javascript
- AJAX file uploads for good browsers with no effort, just make the form pheryfied
- Really small footprint, no external dependencies beside jQuery
- Coded with performance and security in mind
- Code, server and client side, completely commented, all methods have docs
- Javascript config locking and Object.freeze to make it harder for tampering
- The same way you write jQuery in Javascript, you write it in PHP
- Turns static Javascript app code into a dynamic language with a chainable query builder style
- Unit tested, mocha for the javascript and PHPUnit\_Selenium for PHP
- Support for old, new and upcoming jQuery functions out of the box, since nothing is hard coded
- You may nest *PheryResponses* the way you would with jQuery
- You may set Javascript callbacks directly from PHP
- You can call jQuery plugin functions directly from PHP (think colorbox for example)
- Built-in CSRF mechanism that makes each AJAX request signed
- Inline conditional execution using `unless` or `incase`
- Access or call any Javascript code on the page, set/unset variables, add functions to the page on-the-fly
- Plays really well as the transport for client-side frameworks and libraries as such [AngularJS](http://angularjs.org/), [Ember.js](http://emberjs.com/), [Knockout.js](http://knockoutjs.com/), [ExtJS](http://www.sencha.com/products/extjs), [Backbone](http://backbonejs.org/)

Example code
------------

[](#example-code)

Check the a lot of examples and code at

Introduction
------------

[](#introduction)

**This library is PSR-4 Compatible**

The main goal of this library is to make jQuery (and Javascript), be completely dynamic instead of static and unchangeable code, returning commands on-the-fly from the server and execute them in order on the client, while still manipulating the DOM and dealing with callbacks.

This library unleashes everything you expect from an AJAX library, with nested responses, merging and unmerging responses, direct access to the DOM element that is making the AJAX call. It's loosely based on jquery-ujs for Rails concept.

It's a straightforward and powerful AJAX library with direct integration and mapping of all jQuery functions in PHP, the mapping is extended to custom functions set by $.fn, can create elements just like `$('')` does, as **phery.js** creates a seamless integration with jQuery functions, through AJAX to PHP functions, as you can call a PHP function using AJAX

All jQuery functions listed in here are available to call directly from the *PheryResponse* class:  including any new versions of jQuery that comes out, its compatible with jQuery forever, since there are no hardcoded jQuery functions in the PHP code. No need to update phery.js, as it will continue to work with future versions of jQuery automatically (unless jQuery change anything in core that breaks any existing function).

phery.js uses HTML5 `data` attributes to achieve this, and no additional libraries (besides jQuery, since it's a plugin) are needed, even for Internet Explorer. Links and forms will still be able to send GET/POST requests and function properly without when no javascript isn't enabled, because it doesn't use obtrusive techniques and relies on event delegation.

Strict standards for PHP 5.3+ and advised to use jQuery 1.8+. Being just one PHP file, and one javascript file, it's pretty easy to *carry* around or to implement in PHP auto-load scenarios, plus it's really FAST! Average processing time is around 2ms with vanilla PHP, according to Firebug and in the demo page

The *magic\_quotes\_gpc* directive is **DEPRECATED** in 5.3 and **REMOVED** in 5.4, since you are always 100% responsible for the security of your data, so escape your text accordingly to avoid SQL injection or XSS attacks.

All AJAX requests are sent as POST only, so it can still interact with GET query strings, like paginations and such (?p=1 / ?p=2 / ...).

The code is mostly commented using phpDoc and jsDoc, for a steep learning curve, using doc-enabled IDEs, like Netbeans, Aptana, Phpstorm and Eclipse based IDEs. Also, most of the important and most used functions in jQuery were added as phpDoc (from ), as a magic method of the *PheryResponse* class .

What do I need?
---------------

[](#what-do-i-need)

- PHP 5.3.3+
- jQuery 1.8+
- Firefox 3.6+, IE 9+, Chrome 12+, Safari 7+

Upcoming
--------

[](#upcoming)

- Mocha unit tests for the Javascript side running against multiple versions of jQuery on the repo
- PHPUnit\_Selenium test cases for Javascript/PHP testing sources on the repo

Upgrading from &lt; 2.4.0
-------------------------

[](#upgrading-from--240)

Version 2.4.0 isn't a drop-in replacement because of some changes, so you might need to update your code

- All the calls to `PheryResponse::factory()->this()` must be called to `PheryResponse::factory()->this`
- All the calls to `PheryResponse::factory()->jquery()->somemethod()` must be called to `PheryResponse::factory()->jquery->somemethod()`
- If you are using jQuery &gt;=1.9, some functions were removed from the jQuery core, so fix your code accordingly
- If you found yourself adding `data-remote` manually to HTML elements like `stuff`, you have to fix it manually or use the prefered way `Phery::link_to`, since the `data-remote` is now `data-phery-remote`
- The same with `data-confirm`, you have to fix it manually or use the prefered way `Phery::link_to`, since the `data-confirm` is now `data-phery-confirm`

Full PHP API Documentation
--------------------------

[](#full-php-api-documentation)

Installation
------------

[](#installation)

Install Phery with [Composer](http://getcomposer.org):

```
composer require phery/phery
```

Documentation
-------------

[](#documentation)

It's really simple as:

```
