SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    May 2001
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP object to Javascript object

    Sorry if this is not the appropriate place for this.

    Is is possible to convert a php object to a javascript object?

    say something like:
    PHP Code:
    class MyObject{
      function 
    sayHello(){ return "Hello";}
    }

    $myPhpObject = new MyObject(); 
    and then pass that object to a javascript

    HTML Code:
    <a href="#" target="_blank" onclick"saySomething($myPhpObject)">say hello</a>
    Code:
    function saySomething(aPhpObject){
      alert(aPhpObject.sayHello());
    }

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take a look over http://jpspan.sf.net/
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What the status of jpspan for use in the "real world"?

    Douglas
    Hello World

  4. #4
    SitePoint Zealot
    Join Date
    May 2001
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, looks interesting

  5. #5
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DougBTX
    What the status of jpspan for use in the "real world"?

    Douglas
    I started using ScriptServer on a project about a month ago. Converted it to using JPSpan yesterday without a hitch.

    The app I am using it in is basically a form representing a row in the database. This particular table has several 1-to-many realtionships from it, and I use JPSpan to manage those relationships. The user can select a "new" value, click add, and then JS talks to PHP via JPSpan, PHP inserts the new record, queries for all related records, and returns a chunk of HTML representing the full result set, which JS then replaces a div in the document with the updated data. Basically is makes for seamless editing of the related data without posting the main form.

    HTH

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm using parts of jspan too (in particular the http-request layer) that part works well - i should expect the rest to be reasonably stable as well (or it will be within due time)

    the only pitfall right now is in ragrd with recursion - as long as you're handling relative simple objects, this shouldn't be too big a prolem tho'.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •