js libraries and ajax frameworks - php

what's the difference between using a js library like jquery and using an ajax framework what's the most active ajax framework out there( preferably for PHP)
or a better question would be...what's the difference between an ajax request fired with Jquery and an ajax request fired using any "AJAX frameworks"

As PHP frameworks typically sit on the web server and generate web pages that are then rendered by the client, a PHP "AJAX" framework is likely going to generate JavaScript code that is then executed by the web browser. The JS code that gets generated is serving the same role as JS you would write by hand to do the same thing, such as the jQuery.ajax() call you mention.
So, typically, the difference is between code written for you, and code you write by hand.

I think you are confused about what is Ajax and how it is related to PHP. Basically "Ajax" just means that some javascript code is making calls behind the curtains to some backend server to make an action or update something on the user interface.
That backend server language could be PHP, ASP, Ruby or anything really. Thats why the most popular "Ajax Frameworks" (Prototype, JQuery) are purely Javascript, and don't depend on you using PHP or anything.
On the other hand there's PHP Frameworks like CakePHP, CodeIgniter, Zend Framework (or the one you mentioned, Akelos) who just help you doing some tedious tasks in PHP, like templating, database access, etc. These frameworks don't depend on any "Ajax Framework" you can use any of them.
So just look at this separately, there's "PHP Frameworks" and there's "Javascript Frameworks" aka (badly) "Ajax Frameworks".
Of course there's always the exception to the rule, there's some project who make PHP calls to output Javascript code, like Xajax. But i would recommend you to avoid them or you will end up more confused.

what's the difference between using a
js library like jquery and using an
ajax framework like Akelos?
I believe Akelos is a PHP framework and NOT a Javascript framework.

Related

What are use cases for V8 in PHP?

PHP has embedded V8 JavaScript engine, http://www.php.net/manual/en/book.v8js.php. I was wondering what are possible use cases, esp. considering that PHP is synchronous and JavaScript is asynchronous.
A powerful feature of this extension is that the same code can be used both client and server side, reusing implementations of the same code in PHP for server side and js client side.
A possible use case is for providing server and client side validation using the same JS code. Client side, the code would be run in the browser, and server side it's executed using V8JS.
Other potential uses could be templates or any other business logic that's needed both client and server side.
It seems like you'll still be in uncharted territory here, though. I haven't seen any libraries use V8JS for anything like this.
One of the ways I am using JS integration within PHP is to provide a simple manner for end users to safely execute user-supplied code (a.k.a. scripts) within a PHP-based app. With the implicit isolation, one can limit the inputs and functions available to protect both user privacy and system security while allowing a wide range of user-defined scripted actions within the server context.
I must admit that seeing executable javascript code in database records is a bit unnerving at times! You do get over it though. :)
One use case could be server-side rendering for javascript templates or frameworks, SSR for short.
One could write their templates with a javascript framework like Vue.js or react and render it with v8js.
Once php has rendered the template and sent it to the browser the javascript framework could pick this up and make it interactive.
Two benefits here are faster loading web apps and no annoying javascript page flicker.
For building crawler which extracts useful data from HTML emulating Javascript runtime is especially useful, because some HTML data may be hidden/mangled by Javascript code. So unless you would like to write Javascript parser in PHP yourself - the only option is to use V8 engine built already with that purpose.
PHP and Javascript are languages, it doesn't make sense to say one is synchronous and one is not. Informally when one says that, they mean that most of the libraries around that language that use I/O use async/sync IO.
In the core language and V8, nothing is asynchronous.
Why to use it? Javascript on V8 is orders of magnitude faster than the canonical PHP implementation (note that there are other PHP implementations, like Facebook's HHVM) while still being just as powerful scripting language. Normally you would be forced to write a C extension for PHP to get raw performance.
Sorry to bump / add to an ancient question, but a fairly obvious use case in the Web 2.0 / 3.0 era is going to be "when file_get_contents() just won't cut it."
Although it may not be the best choice, PHP also isn't the worst choice for bots, spiders, scrapers, etc. And more and more web pages aren't complete unless the JavaScript on them is executed / rendered.

Use of ajax framework to develop a webapp employing php, codeigniter

I am going to start developing a webapp using php framework codeigniter. The app is going to do most of the database dealing using ajax/jquery. From what I know, I would be implementing the following steps to do a particular task
Create a view page
The events performed on view page's elements, i.e., click, mouseover etc. will be attached to event handler functions in js files included in the view
js functions will be making get, post requests to server side
In case some dynamic values need to be passed to js functions they'll passed using inline php code given below.
On server side, some database queries will be performed to generate a json(sometimes xml) which will be sent as response
Based on the response, the js function callback will manipulate the dom.
Now, my question is whether there is an ajax framework that can further simplify the implementation of steps given above. if not a framework, then may be a better approach to implementing ajax and php.
// This is part of view page
<a href="Delete User" onclick="deleteUser('<?php echo $userid; ?>')" />
Welcome to jQuery. This is not an AJAX framework (I have never heard of one of those) but it is a JavaScript Framework that incorporates some easy AJAX functionality.
Everyone talks about "integrating with the PHP framework!" like its some sort of crazy feature in PHP. JavaScript makes a request to a URL and does something with the response. That URL could be native PHP, CodeIgniter, a static file or bloody ColdFusion, it is all the same.
So if you are using CodeIgniter, in your view put:
$.get('/controller/method/param1/param2', function(data) {
$('div#someid').text(data.whatever);
}, 'json');
I don't really know what you mean by "AJAX framework" and whether you're talking about a clientside or serverside framework.
In the event you're looking for a clientside framework that handles client-server data synchronization, check out http://documentcloud.github.com/backbone/
Codeigniter has a javascript class that might help avoid "the Mess" you spoke of.
http://codeigniter.com/user_guide/libraries/javascript.html

Using Cappuccino JS framework with PHP backend

I have php based application currently written using CI. I want to integrate Cappuccino JS framework at my UI layer. Does anyone know how can one go about doing that?
Cappuccino is a JS framework that brings UI developerment style much like the one you'd have with Apple's Cocoa to the web. So instead of creating HTML pages and then using a templating system to inject variables, the UI is generated purely by Obj-J and Cappuccino (which is pretty cool). Since the UI is coded completely in Obj-J it would be best if calls to the backend were done via ajax (with JSON transport). This can be done the normal way AJAX/JSON is done in javascript since Obj-J is a superset of Javascript. You can find some tutorials about Cappuccino here.
Mind you Cappuccino isn't for the light hearted. Unless you know WHY you're using it, you probably shouldn't be.
You can find a short example of using JSON and cappuccino here:
http://www.nice-panorama.com/Programmation/cappuccino/Tutorial-Login-Step1.html

Ajax library for PHP

What's the best Ajax library for PHP and why do you prefer it?
If you are searching for a library to facilitate Ajax Requests, it is not dependant of the server-side : launching Ajax requests is done on the client-side, in Javascript.
There are plenty of JS Frameworks to do lots of nice things, and, in the middle of those, Ajax Requests.
I've used those ones :
prototype : the one I know the best ; and really like it
jQuery : probably the most used nowadays
MooTools
On the server-side, the JS Framework used doesn't make much different.
You might still want to take a look at the JSON format, which is great to exchange data between client and server when doing Ajax requests. There are several implementations in PHP that allows you to work with that one.
For instance :
With PHP >= 5.2 : json_encode and json_decode ; nice, as provided by PHP
Zend Framework has Zend_Json ; I've already used it on a PHP 5.1 server, outside of Zend Framework ; nice because I like ZF, and this component works on 5.1
If you want other informations, you might edit your question, to be more clear about what you want :-)
For getting data out of PHP — http://uk3.php.net/json
For abstracting XMLHttpRequest in a cross browser fashion, converting JSON to JavaScript objects, and providing ways to insert that data into a document, I tend towards YUI, but this is largely a matter of personal taste.
It's depends on needs, but JSON is also worth a dig;
http://json.org

Is it a good idea to combine an Ajax/UI JS Framework (ext,jquery-ui) with an MVC PHP framework (zend, symfony)?

I realize this is a very generic question, but I guess I'm not really looking for a definitive answer. Being new to PHP frameworks I'm having a hard time getting my head around it.
Javascript frameworks, especially with UI extensions, seem to have their sort-of MVC-like approach by separating your JS code from your design. It just seems like it would get confusing to use an additional MVC framework on the backend.
Is this commonly done for primarily AJAX-driven applications? Is there an accepted/common way of doing it?
It's the next logical step from MVC, in my opinion. You already separate your data access (model), from the business logic (controller), from the output (view) - now you're just separating behaviour from markup.
In my experience, it works really well with AJAX features, since you only need to change your View to return the necessary information as JSON or XML.
A quick example of how it can fit together for a Zend Framework app (and this is from a demo app I wrote a few months ago):
Use the MCV Framework to build a fully functional site (which works without javascript).
Modify the controller to understand the difference between a 'normal' request and an AJAX request (Zend's context switching makes this easy).
Add Javascript (in my example jQuery) to cleanly replace the links with AJAX events.
In the end, the PHP app knows that an AJAX request needs an AJAX response (less bandwidth, less processing, only JSON or HTML 'snippet'), but a normal request needs an entire page generated.
Basically, you're just using AJAX to request (or update, or add data to) the 'view' template, without having to process the entire layout. The Zend Framework Context Switch Action Helper may help this make more sense.
It's worth mentioning that context switching works well in making a request available in different formats - HTML/XML,CSV,etc.
Its a very good idea, since the PHP MVC frameworks are bundled with JS frameworks:
Zend comes with Dojo
Symfony comes with Prototype and script.aculo.us
CakePHP comes with Prototype and script.aculo.us or jQuery (future release)
updated link, thanks "Exception e".
Personally we are using Zend (MVC as well as other aspects of the Zend framework) with jquery and it works very well together. Since not all of your interaction from the html page will be via jquery (ajax) then a standard MVC architecture is highly recommended. You certainly want the layers of your architecture (separating the model and the view) and having jquery is (at least to me) and additional "feature" of being able to execute your MVC asynchronously.
It just seems like it would get confusing to use an additional MVC framework on the backend.
No need to worry about that. You can use zend framework and extjs for example independently while developing, they are really separate products. The dependencies between these layers should be kept simple. No need to worry.
The coupling is low, you only need to set up means to query data from your server-app and do whatever you want with in on the client side. The line between these systems is simple and won't confuse you.
Extjs doesn't really has an mvc structure imho. It offers predefined rich components. You glue these components with some configuration and set up the urls of your server where data can be fetched from.
How do you get your zend mvc respond to ajax? I recommend you to view the presentation about zf ↔ ajax from the zf's project lead.

Categories