passing variables between flex and php - php

i am new to flex development my question is How do i pass variables between flex 3 and a mysql database using php? i was told the best way is to AMFPHP but that seems like an over kill or may be not am not sure.. any ideas?

I'd use json over xml since json will transfer less bytes and php's json_encode($object) is quick and easy.
I'd use json over amfphp because json is general purpose. For example, I can create a web service for flex or javascript by returning json.
You might have a look at this article for comparison between json, amfphp, and xml. Also, here is a nice tutorial on flex, php, and json.

AMFPHP is not really being actively developed. The best alternative right now is to use Zend_Amf http://wadearnold.com/blog/?page_id=155, which is supported by both Zend and Adobe.
Don't be scared by the need for Zend Framework components. The framework is modular, and you can use your own custom php classes for accessing data without having to incur the Zend Framework learning curve.
The great thing about using AMF is that since it is a binary data transfer, it's very fast.
Also, working with XML or even JSON, is an annoying extra step if you just want your flex app to get results data an api call. If, for some reason, you need to also handle outputting data to xml or json, that can easily be added to your app by extending or creating new controllers/services that translate the data from arrays and objects to xml or json

There's a few choices open to you. Essentially, it boils down to how you'd like to deal with the data on the PHP side of the fence.
The two I'd spend time investigating would be simple XML (my first preference) and AMFPHP.
XML:
Flex can work very easily with XML data, even mapping it automatically to/from ActionScript objects (generically, or with something like the xobj project on GoogleCode, to typed instances). Similarly, there's plenty of support available for working with XML in PHP code.
AMFPHP:
AMFPHP gives you way to pass typed ActionScript objects over the wire to your PHP code. There's tooling included in the AMFPHP project that makes working with MySQL on the PHP side easy too.

If you are doing a simple query, I would pass your data as plain POST data. You can do this using HTTPService component in Flex. On the PHP side I would respond with an XML string and set the HTTPService resultFormat to "e4x" (Ecmascript for XML), for an easy object-like manipulation of the result data.
Here is the livedocs reference for HTTPService: http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_2.html
For more complicated queries/operations, there is also the option of using the Flex RemoteObject with AMF as the data protocol. On the PHP side you can then use the zend framework AMF component to communicate.
Here is the livedocs reference for RemoteObject: http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_4.html
And the download page for Zend AMF: http://framework.zend.com/download/amf

Related

AngularJS unserialize PHP string

I have a PHP project which provides a api endpoint exposing JSON data. Part of that data are serialized strings generated in PHP.
In a nodejs application I can unserialize that data using the php-unserialize package. However, I am a complete beginner at Angular and can't find a similar package for AngularJS.
I would appreciate some direction on how to unserialize a string into JSON data in AngularJS
and, where I can find AngularJS packages?
The AngularJS framework does not have a service that decodes array and objects serialized by PHP serialize.
Instead encode using PHP json_encode.
I seriously recommend that PHP APIs avoid using serialize to communicate data.
From Anonymous:1
Please! please! please! DO NOT serialize data and place it into your database. Serialize can be used that way, but that's missing the point of a relational database and the datatypes inherent in your database engine. Doing this makes data in your database non-portable, difficult to read, and can complicate queries. If you want your application to be portable to other languages, like let's say you find that you want to use Java for some portion of your app that it makes sense to use Java in, serialization will become a pain in the buttocks. You should always be able to query and modify data in the database without using a third party intermediary tool to manipulate data to be inserted.
I've encountered this too many times in my career, it makes for difficult to maintain code, code with portability issues, and data that is it more difficult to migrate to other RDMS systems, new schema, etc. It also has the added disadvantage of making it messy to search your database based on one of the fields that you've serialized.
That's not to say serialize() is useless. It's not... A good place to use it may be a cache file that contains the result of a data intensive operation, for instance. There are tons of others... Just don't abuse serialize because the next guy who comes along will have a maintenance or migration nightmare.
The JSON Standard is well supported by most languages and widely used for data interchange on the Web. The AngularJS $http service supports it automatically by default.

Get PHP JSON Data in Android

I do alot of development in PHP. And I have recently started working with JSON data for various APIs for my websites to interact with each other. I would like to extend this a little further and create a Android app with my web applications.
Please keep in mind I am fairly new at Android and have little experience. I have worked with JSON data in JavaScript, and it is fairly easy. However that is using jquerys easy to use Ajax .post.
So my question is, what is the easiest, most simple way to get JSON data from a website and turn it into a working variable in Android?
I would prefer something with no error checking or anything. Just the basics.
Thanks!
If you're programming object oriented, there is not any easier way then to do it with JSON, so this is a good choice.
You can use Google's Gson to parse the Json strings your PHP back-end sends to your Android app.
As long as you use Objects, you can parse the string into an object with 1 line of code. Just be sure to type all fields correctly on your PHP side.
Take a look at this tutorial, I used this a while back and it makes it pretty clear :)
As #alexander7567 mentioned, GSON is also very good to use. But may be a bit more complex for you to pick up at first!

RESTful API in PHP for a script outputting in JSON format

I am a PHP programmer and new to RESTful services. I have developed a page which outputs the data in JSON format, based on query parameters (_GET). Now I wan't to implement it so that I can call my script with different parameters via REST API.
My question is, how would I go about implementing the API in PHP. Basically, I am developing this so we can integrate the same data that is there on our website in a different interface for our client sites.
I already have most of data exposed in JSON format, just need guidance on how to implement the RESTful service for that.
are you comfortable with php frameworks? than you should give a shot to laravel php framework its is really awesome with low learning curve.
You can use json_decode of php and you will get array. You can use decoded array values for further processing. You can make a http post request or curl alternatively to make a rest request.
Or you could use Slim if you don't like Laravel for some reason. Take a look at https://github.com/victorjonsson/PHP-Rocker it will get you up an running in minutes

Invoking C++ functions from a REST based web service

I have a C++ API (back-end) and I'd like to use it as a web-service. I am thinking of using REST as an interface between the front end and the back end. I found a bunch of C++ libraries for REST, but what I ultimately want is to keep the C++ API clear/independent of the REST stuff, and handle all of that in the front end, thus keeping the C++ API general purpose and reusable. Any suggestions on how to go about it?
Also, my API is not focused on collections of data, but on processing the data that will be given as an input to the functions contained in the API. So basically, the C++ functions receive input data from the web, process it and return output data. I just need to be able to make API calls passing the input data as parameters and get output data back.
So I'm guessing from the tags that you want a PHP server that calls C++ functions?
If so, you can call c++ routines directly from the PHP code using PHP extensions. Alternatively, create a wrapper for your C++ code using SWIG, or put your C++ routines in a executable and call it using system() passing the parameters as standard input.
The way I do this kind of thing is using a PHP frontend talking to your C++ backend via sockets.
You'll need wrapper layers at the C++ and PHP sides to serialize/deserialize your calls. For this there is any number of solutions: you can use XML, JSON, AMF, protocol buffers, thrift, etc.
This can scale nicely as you can have multiple PHP frontends calling your C++ backend - but is only really necessary if your backend is stateful.
If the backend is not stateful then you're better off just using system style calls.
I think you can create a wrapper for your API, transform your api functions into rest endpoints, and use DTOs to decouple the REST layer from your api, for this you can use otapp, a very complete rest framework in C ++.

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

Categories