SCPHP Tutorial - Creating Windows

This tutorial will show how you can create a window with SCPHP. We will create a empty page, load SmartClient and show a nice window. The complete source-code is available at the end of the page.

1) Make sure that you already installed SCPHP

If you have not installed SCPHP yet, check the Installation page.

2) Create a new php page and include scripts

Create php page with the following content:

<html>
	<head></head>
	<body>
		<?php
		// Auto load function
		function __autoload( $className )
		{
			require_once( 'SmartClient/'. $className .'.php' );
		}
		
		$scWindows = new ScWindows();
		
		// Include SmartClient scripts
		echo $scWindows->includeScripts();

We first declare the __autoload() function. This isn't a required step, but it is a good idea because it make loading SCPHP classes really easy. You could also use a simple require for the class that you need to use.

After that, we create a new instance of ScWindows class.

And finally, we call includeScripts(). This is a function that automatically include the SmartClient scripts.

3) Create the content

Add the following code to the script:

		// Add htmlFlow with content
		$scHtmlFlow = new ScHtmlFlow();
		echo $scHtmlFlow->create( 'elementID' , 'Text text text!' );

A htmlflow is used to hold content. In this part of the script, we basically create a new instance of ScHtmlFlow and draw a new htmlFlow with:

  • ID: elementID
  • Content: Text text text!

4) Create the window

Add the following code to the script:

		// Add item and windows
		$scWindows->addItem( 'elementID' );
		echo $scWindows->create( 'windowID' , 'Title of the Window' , 640 , 480  );
		
		?>
	</body>
</html>

Now, as we have the content, we can create the window.

On the first line, we add an item. Note that when you add a item, you use the ID of the element that created on step 3.

And finally, we draw the window with the following attributes:

  • ID: windowID
  • Title: Title of the Window
  • Width: 640
  • Height: 480
Loading content from an external URL
After the height parameter, you can add a URL to load the content ( instead of creating the content with a htmlFlow or other component ). Example:
echo $scWindows->create( 'windowID' , 'Title of the Window' , 640 , 480 , 'myscript.php?anything=you_want' );

5) Full source code

Here it is the full source code of the script used on this tutorial:

<html>
	<head></head>
	<body>
		<?php
		// Auto load function
		function __autoload( $className )
		{
			require_once( 'SmartClient/'. $className .'.php' );
		}
		
		$scWindows = new ScWindows();
		
		// Include SmartClient scripts
		echo $scWindows->includeScripts();
		
		// Add htmlFlow with content
		$scHtmlFlow = new ScHtmlFlow();
		echo $scHtmlFlow->create( 'elementID' , 'Text text text!' );
		
		// Add item and windows
		$scWindows->addItem( 'elementID' );
		echo $scWindows->create( 'windowID' , 'Title of the Window' , 640 , 480  );
		
		?>
	</body>
</html>
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.