Freigeben über


Working with Microsoft Silverlight on PHP

Architecture diagram for an embedded Silverlight controlSilverlight Microsoft Silverlight, now at version 3.0, is a great way to create rich web applications that run on Windows, Mac OS and Linux. It provides an engaging, rich, safe, secure, and scalable cross-platform experience. Best of all you can run it off any web server (IIS, Apache for e.g.) and it can be called from any PHP website! Our team has released some helper samples to get you started. You can find the project on the Samples for PHP with Silverlight web page, and the project source can be found on Codeplex. The project includes sample HTML and PHP scripts.

How it works? Silverlight content is embedded into an HTML or PHP web page and in turn is transferred to the client browser where it is displayed by the Silverlight runtime (plugin) installed on the client computer. The architecture is shown on the right.

You will first create a Silverlight application file (.xap). We have provided a sample file, HelloPHPDevelopers.xap within the download or you can also create one for yourself by using another tech bridge we have, Eclipse Tools for Silverlight. Our colleague Steve Sfarz in France has a great post up on his site describing how to get started with it and create your own .xap file. This file is essentially a packaged archive or .zip file (try changing .xap to .zip and browse into it) with a collection of libraries that you have compiled for your application. If you follow the directions on the site you will end up with a button on a form with some custom actions.

You will then copy the .xap file you have created to a directory within your web site where you plan to host the Silverlight content. You will then want to create a custom HTML or PHP page that includes the following code in it’s body

image 

That’s all you need to run the .xap file you created and you can swap it out to any other file Silverlight application you choose to use.  If a user does not have the Silverlight plugin installed they will be presented with a 'Get Microsoft Silverlight' image and a link to install the plugin too. You should see an example of this in action right below this paragraph.

 

To do this dynamically from PHP, you can use the function below. This is handy if you have Silverlight content in more than one place on your website.

image

That’s all you need to take advantage of Silverlight as a content source for your PHP website. Have fun and share your experience back with us!

Jas Sandhu
Technical Evangelist, Interop Vendor Alliance Manager, Interoperability Strategy Team
Twitter@jassand, FriendFeed@jassand

Comments

  • Anonymous
    November 13, 2009
    good idea .

  • Anonymous
    November 17, 2009
    Why not support using Phalanger to directly code your Silverlight applications in PHP? With Phalanger, PHP becomes a .NET language that can be used to write applications targeting the .NET platform, including Silverlight. Maybe you guys could work on integrating Phalanger as part of the core framework for web applications, or at least pay for a team of people to work on improving it and bring it up to par with the Zend PHP implementation.

  • Anonymous
    November 19, 2009
    @king that's an interesting suggestion. Solves another set of questions. Are there a lot of users? I would be interested in chatting with some of you!