PHP Method Call via URL

We are developing a Flex Application with PHP as a middleware. Flex Httpservice component we are using to communicate with the PHP. We have several developers who are doing separate modules. They doing both Flex as well as PHP code. I thought its not proper and need to have a solution where our code will reside on the single url.

How we achieve this?

I thought of developing a architecture which will take a className and methodName from URL and call methods and the supplied object dynamically.

eg. http://localhost/PHP/Flex/index.php?className=MyClass&methodName=getUser

This above url calls getUser method on MyClass Object. I used call_user_method function of PHP which allows me to achieve this.

One trick for this part is also instantiating the object dynamically. I coded like this

function getObject($class)
static $instance ;

$instance =& new $class;

return $instance;

getObject method accepts className and checks wheather that object exists or not. If object is not set then it creates a object and just return it.

It was a great experience while building something which allows my developers to simplify their code integration. Now every developers is working on their respective classes and using this method.

Cheers šŸ™‚

5 Responses to PHP Method Call via URL

  1. Hey Nice piece of work.Appreciated.

  2. rajeshbhadra says:

    vijay you should post some example.That will be more clear to fellow flex developers who are trying to learn Flex and PHP. šŸ˜‰

  3. @rajesh,
    Thanks for this suggestion, I will post some example which will be real useful.

  4. Chris Peters says:

    You may want to look at the Zend Framework. The Zend_Controller package already does the stuff you’re looking for. Google “zend framework tutorial” for some tutorials to get you started.

  5. Preetul says:

    Really great work.Appreciated.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: