Click here to Skip to main content
13,090,730 members (45,626 online)
Click here to Skip to main content

Stats

35.5K views
345 downloads
30 bookmarked
Posted 22 Feb 2009

Simulating .NET's ScriptService in PHP

, 22 Feb 2009
An easy-to-use class that allows us to create PHP classes whose methods are automatically exposed in client-side JavaScript.
<?
// MyScriptService.php

// Clayton Rumley, digifi inc., clayton@digifi.ca
// www.digifi.ca

include_once 'digifiss.php';

class MyScriptService extends DigifiScriptService
{
  //This is a public function which will be turned into a ScriptMethod
  public function HelloWorld()
  {
    return "Hello World";
  }
  
  //A ScriptMethod with arguments:
  public function Add($x, $y)
  {
    return $x + $y;
  }
  
  //A private method, will be ignored by the JavaScript generator:
  private function DoSomethingPrivate()
  {
    return "Not Exposed";
  }
}

//This is the only line of initialization required:
new MyScriptService();
?>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Clayton Rumley
Software Developer (Senior) digifi inc.
Canada Canada
Clayton Rumley is web developer for hire from Winnipeg, Manitoba, Canada.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 22 Feb 2009
Article Copyright 2009 by Clayton Rumley
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid