Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Description

This example shows us how to PHP with SmartClient framework.

SmartClient applications are single page applications most of the time. All the javascript and HTML is loaded or generated dynamically, and most of the time users don't need to leave the initially loaded page. 

Prerequisites

  • In order to connect the database, You need to download the ReadBean ORM Library. The ReadBean PHP ORM library can be download here.

Setting up the application

This example shows how to use the PHP with SmartClient ListGrid component, by connection ReadBean ORM library with a ListGrid. The following steps are required:

  1. Create server-side code to fetch data from database and respresent it in the JSON format necessary for SmartClient components:
    1. This code will perform the fetching and return the response in JSON format:
      1. Please create the fetch.php.

        fetch.php
        <?php 
            // importing the ReadBean library
        	require 'rb.php';
        	// Including the DResponse source
            require 'DSResponse.php';
        	
            // Connecting to the database	
        	R::setup('mysql:host=[HOSTNAME];dbname=[DB_NAME],'USER_NAME','PASSWORD');			
        	// Get the data source list
        	$products = R::getAll('Select * from supplyitem');
        	// Disconnect to the database
        	R::close();
         
            // SmartClient accept JSON in special format, 
        	$response = new DSResponse();	
        	$response->setProducts($products);
        	$response->setStartRow(0);
        	$response->setEndRow(count($products)-1);
        	$response->setTotalRows(count($products));
        	$response->setStatus(0);
        	// Convert from DResponse Object to Array for JSON encoding
        	$result['response'] = (Array)$response;	
        	// Create JSON from php data structure and output it.	 
        	echo json_encode($result); 
        ?>
    2. dsf

 

 

  • No labels