Announcement

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

    #16
    Originally posted by kccheng
    I believe all backend face th same problem, not just PHP.
    For me, since my PHP is used to access MySQL, so I use MySQL's
    user to protect the PHP code.
    maybe i described my problem wrong. of course i protect the mysql-database with an mysql user and password. but what prevent anybody just to call "www.example.com/php/myphpfile.php?delete=anything" and manipulate the database this way? Anybody can send a POST or GET request to my php-script right now and my question ist how could i change this?

    Comment


      #17
      Help

      I'm trying to deploy a rest php with an hardcoded response, but the grid stucks on "Loading data..."

      Here is the php code:
      Code:
      <?php
              $json = array();
              $json['response'] = array();
              $json['response']['status']    = 0;
              $json['response']['startRow']  = 0;
              $json['response']['endRow']    = 1;
              $json['response']['totalRows'] = 2;
              $json['response']['data'] = array();
      		$json['response']['data'][0] = array();
      		$json['response']['data'][0]['ipAddress'] = "128.0.0.1";
      		$json['response']['data'][0]['hostName'] = "host1";
      		$json['response']['data'][1] = array();
      		$json['response']['data'][1]['ipAddress'] = "128.0.0.2";
      		$json['response']['data'][1]['hostName'] = "host2";
      		echo json_encode($json);
      ?>
      Here the extended RestDataSource:
      Code:
      import com.smartgwt.client.data.RestDataSource;
      import com.smartgwt.client.types.DSDataFormat;
      import com.smartgwt.client.data.fields.*;
      
      public class SimpleRestDataSource extends RestDataSource {
      
      	public SimpleRestDataSource() {
      		int minWidth = 100;
      
      		DataSourceTextField ipAddressField = new DataSourceTextField(
      				"ipAddress", "Ip Address", minWidth);
      		ipAddressField.setRequired(true);
      		ipAddressField.setPrimaryKey(true);
      
      		DataSourceTextField hostNameField = new DataSourceTextField("hostName",
      				"Host Name", minWidth);
      
      		setFields(ipAddressField, hostNameField);
      
      		setDataFormat(DSDataFormat.JSON);
      		setFetchDataURL("php/assetDS.php");
      		setAddDataURL("php/assetDS.php");
      		setUpdateDataURL("php/assetDS.php");
      		setRemoveDataURL("php/assetDS.php");
      		setClientOnly(false);
      	}
      }
      And here the snippet for the grid:
      Code:
      ListGrid grid = new ListGrid();
      	    grid.setDataSource(new SimpleRestDataSource());
      	    grid.setAutoFetchData(true);  
      	    panel.addMember(grid);
      What's wrong? If that's right, what else could it be?
      Thank you, caru.

      Comment


        #18
        It should work. The only difference between your code and mine is, that you set
        Code:
        grid.setAutoFetchData(true);
        . I use
        Code:
        grid.fetchData();
        to fill my grid, but this shouldn'nt make any difference.
        Maybe you try to your code with the google web toolkit development shell. If you do so be aware, that you have to configure the included webserver to execute the requested php-script and not just display the code. You can solve this problem easily by compiling your code and try your application on your own webserver which should be able to execute php-scripts.

        Comment


          #19
          Help

          Thank you for your help, but I forgot to mention that I actually tried the app on a real webserver with php 5.2... so that's not the problem.

          Comment


            #20
            I found the problem... it was the "real server" :-/ I'm very sorry for having taken your time, but when I tried it with another server of another hosting company, everything went well... anyway, thank you for your interest!
            What can be wrong with the first server? Please note that if I try to access the .php directly I correctly get the json printed out on the page...

            Resolved: the first server is a cheap hosting one, and attacches a google analytics script at the end of each page, including to the JSON returned by the php. So, nothing to do with SmartGwt, which behaves appropriately.
            Last edited by caru; 25 Mar 2009, 19:30.

            Comment


              #21
              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.

              This code is also generic across different DataSources - similar to how our Java server uses an XML definition of the DataSource, this PHP code parses JSON DataSource definitions (isc.RestDataSource.create({..})) so you only define your DataSource in one place and both client and server behaviors result from it.
              Last edited by Isomorphic; 8 May 2013, 12:48.

              Comment

              Working...
              X