Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SGRJP: Smart-Gwt-Rest-Json-Php library

    Hello,

    I just finished a quick attempt to bridge SmartGWT 2.5 with php. You can find the library here:

    http://scalingexcellence.co.uk/sgrjp...on-php-library

    This library provides some helpers that should make integrating with php as easy as essentially 4 lines of code (see the example below). It supports CRUD, server side filtering and sorting. It intentionally doesn't provide authentication or other application specific aspects in order to be as generic and reusable as possible.

    Right know I provide an example implementation with MySQL database back-end. It should be quite easy to make it support MongoDB, CouchDB and ORM's and semi-trivial to support other SQL based languages.

    Use (MySQL example):

    Code:
    require_once(dirname(__FILE__).'/lib/sgrjp.php');
    require_once(dirname(__FILE__).'/lib/mysql.example.php');
    
    $ob = new sgrjp();
    
    try {
        //Open a connection
        if (!mysql_connect('localhost', '...', '...')) {
            throw new Exception("Can't open MySQL connection. Wrong username/password?");
        }
    
        //Configure and select db
        mysql_query("SET CHARACTER SET utf8");
    
        mysql_select_db("sgrjp");
    
        $pks = array("ItemsDs"=>array("SKU"), "supplyCategoryDS"=>array("categoryName"));
    
        //Retrieve the request object
        $req = $ob->decodePostAndGet();
    
        //Convert the request to an SQL query using our example MySQL parser and run
        list($ds, $total) = sqlparser::run($req, $req->ds, $pks[$req->ds], false);
    
        mysql_close();
    
        //Return the results as a properly formatted JSON object
        $ob->returnResult($ds, $req->startRow, $total);
    This doesn't intent to become as complete as the Java Server-side solution SmartGWT provides, but it can still help anyone who has to interface SmartGWT with php and doesn't want to reinvent the wheel.

    Please tell me your thoughts, if you find it useful etc.

    #2
    This looks quite good neverlastn, thanks for posting.

    Comment


      #3
      Hello Isomorphic,

      Thanks a lot for writting such a great library as SmartGWT :)

      Best regards,
      Dimitris

      Comment


        #4
        This looks perfect for my project. I always appreciate it when someone goes out the way to provide a nice clean solution for everyone. Thank you very much for all your effort.

        This is my first SmartGwt project, and I have a hard requirement that a PHP Server be used. Can I ask, if I require more functionality than this, what would be a good PHP alternative for SmartGwt <-> MySQL?

        Comment


          #5
          Propel or Doctrine are both popular ORM solutions for PHP, with roughly similar user bases and functionality.

          Comment


            #6
            I'm looking to recreate your project using Propel. I can see only mysql.example.php and index.php would need to be modified. This would allow server-side validation to be easily implemented using the automatically generated stub classes from Propel. It should significantly clean up the mysql.example.php code too.

            I'm fairly new to PHP so hopefully this will be a decent attempt. I was wondering if you found a documented list anywhere of RestDataSource fields, values and operators, or did you simply reverse engineer the protocol through the RPC Manager?

            Comment


              #7
              Look at the JavaDoc for RestDataSource, it explains all this in great depth. However first, go back to the QuickStart Guide, as you should already have been aware of the RestDataSource docs if you'd read the Data Integration chapter.
              Last edited by Isomorphic; 13 Mar 2012, 10:05.

              Comment


                #8
                On the public wiki there is now a series of articles showing how to build PHP server code for RestDataSource that supports full CRUD, including AdvancedCriteria and transactional commits to a database (using the RedBean PHP library). Take a look here.

                Comment

                Working...
                X