With the PHP Toolkit you can do three things:
A discussion forum is here: http://groups.google.com/group/phptk
You can contact the author at: MacPgmr (at) fastermac (dot) net
Author: Phil Hess.
Copyright: Copyright (C) 2008 Phil Hess. All rights reserved.
License: All source code developed for the PHP Toolkit is released under the Modified LGPL license.
You can use a local Web server for testing.
If you have Delphi for PHP 2.0, it includes Apache 2.
http://www.hostlibrary.com/installing_apache_mysql_php_on_linux
You will need PHP 5.1.0 or later. The Toolkit was developed and tested with PHP 5.2.4.
http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105
For Tiger (10.4), download the PHP 5.2.4 or later installer (.dmg file) from:
VCL for PHP is the open-source PHP class library that is used to run forms converted to PHP. The Toolkit was developed and tested with VCL for PHP 2.0, build 2008-05-19, available here:
Note that if you have CodeGear's Delphi for PHP (version 2.0), you already have this release of VCL for PHP.
You will need one of these compilers:
If you intend to configure Lazarus as a PHP IDE, you'll need the Rhino JavaScript interpreter for Java (js.jar) and the JSLint JavaScript Verifier script (jslint.js):
http://www.jslint.com/rhino/index.html
These two files are used in conjunction with the CheckJS utility included with the PHP Toolkit. Place js.jar and jslint.js in the same folder as the compiled CheckJS.
If you use Firefox, you'll find the following add-ons useful:
Finally, if you use iCab on OS X, you'll find several developer-oriented tools on its Tools menu:
If you want to learn more about writing PHP extensions or using PHP with Delphi, you will want version 7.0 or later of Serge Perevoznyk's PHP4Delphi, available here:
http://sourceforge.net/project/showfiles.php?group_id=48329&package_id=94501
Serge's home page is here:
http://users.telenet.be/ws36637/php4delphi.html
Note: PHP Toolkit includes the PHP/Zend types units from PHP4Delphi, but the Toolkit's ExtPZAPI unit only includes the minimum PHP/Zend API functions required for the example PHP extension. PHP4Delphi includes the full PHP/Zend API, plus components for using PHP with Delphi.
With Delphi: dcc32 fmtophp.dpr
With Free Pascal: fpc fmtophp.dpr
Tip: You can also compile from the IDE. With Delphi, open file fmtophp.dpr; with Lazarus, open file fmtophp.lpi.
With Windows: fmtophp
With OS X and Linux: ./fmtophp
fpc checkphp.pas
fpc checkjs.pas
In the Toolkit's hello folder you'll find the source for a simple Delphi/Lazarus hello app. Convert its two Delphi .dfm files (or Lazarus .lfm files) to PHP as follows from the command line in the hello folder:
With Windows: ..\fmtophp hellomain.dfm helloabout.dfm hello.php
With OS X and Linux: ../fmtophp hellomain.dfm helloabout.dfm hello.php
This will create hello.php and hello.xml.php. Copy these two files, along with the supplied helloajax.php, to your Web server's deployment folder and open hello.php in your browser (but first see Deploying VCL for PHP apps). Here's what the hello.php page should look like:
http://web.fastermac.net/~MacPgmr/PHP/hello.php
Once you have this working, try adding some code to hello.php. For example, open hello.php in a text editor and replace the alert() call in the Button1JSClick event handler with this bit of JavaScript:
findObj("Label1").innerHTML = "Hello, world";
Now reload the page and click the Say Hello button. "Hello, world" should appear in the panel.
Now replace the alert() call in the Button2JSClick handler with this JavaScript:
doAjax("helloajax.php?Name=Label1");
Now reload the page and click the Say Hello Again button. "Hello, again" should appear in the panel. This bit of JavaScript makes an Ajax call to the helloajax.php script on the server, which returns to your browser the same JavaScript that you added to the Button1JSClick function.
Finally, replace the alert() call in Button3JSClick with this JavaScript:
AboutBox_Window.show();
And replace the alert() call in AboutBox_Button1JSClick with this:
AboutBox_Window.close();
Now reload the page and click the About button. The About box should appear. Click its OK button to close it.
In the Toolkit's extension folder you'll find the source for an example PHP extension written in Pascal. You can use one of the supplied batch or script files to compile it from the command line in the extension folder. For example:
With Delphi 7: compext-d7 testext1
With Free Pascal on OS X: ./compext-mac.sh testext1
And so forth. The batch and script files are not really required and are provided for your convenience. You can also compile a PHP extension from Delphi or Lazarus by creating a project file for the library.
Important! On OS X, be sure to use compext-mac.sh when compiling an extension. Since a PHP extension on OS X must be a loadable module rather than a normal shared library, this script alters the normal Free Pascal linking to create a module instead of a shared library.
Compiling the example creates testext1.dll on Windows and libtestext1.so on OS X and Linux. Copy this file to your PHP extensions folder.
To test the example extension, run the supplied PHP script as follows:
php testext1.php
Tip: If you don't know where your PHP extensions folder is located, just run the example's PHP script anyway. PHP will tell you that it can't find the extension and indicate where it's looking for it. That's your PHP extension folder.
Tip: On OS X and Linux you'll probably need to use sudo to copy the file to your PHP extensions folder.
To deploy to a Web site, copy the entire vcl folder to your server's deployment folder. If you don't have much space on your server, then at a minimum create a folder named "vcl" in your Web server's deployment folder and copy all of the VCL for PHP .inc.php files to it, as well as its qooxdoo, js and xajax folders.
Tip: You can set the vcl folder permissions so that only the owner has read privileges. That way it won't be visible to others via their browser.
If you're also deploying Components 4 PHP Lite, create a folder named "components4phplite" in the vcl folder and copy its .inc.php files to the components4phplite folder. Also copy its themes folder to the components4phplite folder. If you're deploying Components 4 PHP Full, the folder name is components4phpfull.
Copy files like hello.php, hello.xml.php and helloajax.php to your Web server's deployment folder (one level up from the vcl folder you created).
Copy any PHP extension libraries that your app needs to your Web server's PHP extensions folder.
Important! If your Web server has disabled the dynamic loading of extensions (via the PHP "dl" function), you will have to load your extensions when PHP starts up via its php.ini file. To determine if "dl" is disabled, run this PHP script on your Web server:
<?php phpinfo() ?>
Then search for "enable_dl" and look at its setting.
You can also use Lazarus for basic VCL for PHP development by adding several external tools to its Tools menu. Choose Tools | Configure custom tools, then click the Add button to add the following commands to the Tools menu:
Caution: As long as you haven't added any code yet to your .php file, you can continue to use Tools | Convert Forms to PHP to create both the .php and .xml.php files. However, if you've added any code to the .php file, this code will be lost since the file is overwritten.
Here's as good a definition as any, from Steve Cooney:
"[VCL for PHP] is a server side class library written in PHP that emits HTML/XML/Javascript that is consumed by a DHTML enabled browser."
VCL for PHP has classes, properties, events and methods that are very similar to Delphi VCL and Lazarus LCL classes, properties, events and methods, which make it easy for the Delphi/Lazarus programmer to learn.
The VCL for PHP documentation is here:
The FmToPhp converter creates a working PHP app from your form that you can run with VCL for PHP without any programming on your part. Of course, the app it creates is just a pretty face and doesn't do much, but you can start adding code to the event handlers to get your feet wet.
Try one of these two forums:
Let's assume you already know Object Pascal and user interface design through working with Delphi or Lazarus. PHP isn't hard to learn, although the syntax is more like C than Pascal. Since PHP is dynamic and interpreted, you can start adding code to your converted forms without worrying about compiling and linking. Just add the code and run it.
PHP makes a good Web server language for a number of reasons:
The PHP manual is here:
http://us.php.net/manual/en/index.php
Developing any Web app that uses Ajax means you'll need to learn a bit of JavaScript at some point since that's the language that the browser understands. One advantage to learning some JavaScript is that it allows you to do more on the client side without sending so many requests to the server, thereby speeding up the app as far as your users are concerned. You can output JavaScript from your PHP code using echo or you can drop "out" of PHP and write JavaScript code directly. See Example 1 above for examples.
Documentation for JavaScript and the browser's DOM objects is available here:
http://developer.mozilla.org/en/JavaScript
Another handy reference is here:
You don't want to include any VCL or LCL code in your extension since the extension will be executing on the server and not the desktop. This means you shouldn't use any units like Forms, Dialogs, Controls, StdCtrls, ExtCtrls, Buttons, ComCtrls, etc. or any units that depends on these units. You should only use non-visual RTL units like SysUtils, StrUtils, DateUtils, Variants, Classes, Math, etc. You can also use the Windows unit on Windows and the Free Pascal Unix unit on OS X and Linux.
The PHP Toolkit does not support PHP 4. VCL for PHP was originally developed with PHP 5.1.3 so you should have at least that version or later if you're working with VCL for PHP. Delphi for PHP 2.0 includes PHP 5.2.2.
If you're developing PHP extension libraries and you don't have at least PHP 5.2.0 you will need to change some defines in PHP.INC.
If you're still intending to work with Pascal, here are a couple of other things to look at for Web development:
VCL for PHP does not have an equivalent control. However, you can use the JTGrid control from the inexpensive Components 4 PHP Lite from JomiTech:
Ajax stands for Asynchronous JavaScript and XML and it's a clever technique for making your Web app feel more like a desktop app. But before we discuss how VCL for PHP uses Ajax, let's talk about how a Web app is constructed with VCL for PHP.
When a .php page is loaded on the Web server, the server executes the page's PHP code with its PHP interpreter module. The VCL for PHP code included at the top of the .php file loads and processes the page's .xml.php file, generating HTML and JavaScript that the server sends to the browser on the client computer. Any JavaScript event handlers in the PHP code are also executed in order to generate the JavaScript event handling code. It's this HTML and JavaScript that the user sees and interacts with. In other words, the HTML and JavaScript running in the browser is your Web app's user interface, not the PHP code that generated it. You can see this auto-generated HTML and JavaScript by looking at the loaded hello.php page's source in your browser.
While developing a VCL for PHP Web app you might start thinking of the PHP code you write as the user interface, but it's not. It's easy to make this mistake because the HTML and JavaScript generation is done for you automatically. Sure, you can output JavaScript yourself in your PHP code if you need to (using echo), but initializing controls is mostly done behind the scenes. More accurately, the PHP code is really two things: (1) the generator of HTML and JavaScript and (2) the handler of requests passed to it via Ajax.
In a traditional HTML page that includes a button, clicking the button submits the page's form to the Web server, which generates a new page based on the form's data that it sends back to the browser. This results in an unsightly redraw of the entire page and can also involve a delay before "control" is returned to the user if generation or transmission of the new page takes time. With Ajax, when you click the button, the JavaScript event handler sends a request to the PHP code on the server, but doesn't submit the form and doesn't wait around for the server to respond to its request (why it's called "asynchronous"). Instead, the XML and JavaScript sent back by the server is handled by a JavaScript "listener" that can update any part of the page. This results in a smoother page refresh and generally feels more responsive to the user.
Note that while your Web app's user interface runs in the client's browser, most of the app's actual work is typically done on the server. For example, the server-side PHP code might read and write data, do database queries, generate a report, run a computational model, etc. when requested by an Ajax call. Much of this processing could be done in a PHP extension library that you develop with Pascal. Remember that the browser JavaScript code will not have access to files or services or programs on the client's computer, so this sort of processing will need to be done on the server.
PHP Toolkit's approach to Ajax
VCL for PHP components have an ajaxCall method that you can use in your JavaScript event handlers to generate JavaScript code that makes an Ajax call to server-side PHP code that you include in your .php page file. However, this approach can be a bit slow, so the FmToPhp converter by default generates a JavaScript function (doAjax) that you can use to call server-side PHP scripts. Scroll down to the bottom of the converted hello.php file to see the JavaScript code that FmToPhp generates. The Toolkit's approach uses the browser's JavaScript XMLHttpRequest object to make the Ajax call, as described here:
http://developer.apple.com/internet/webcontent/xmlhttpreq.html
Note that you can use the VCL for PHP ajaxCall approach if you want. Just include the -c switch when converting your forms. When the -c switch is used, FmToPhp does not generate the XMLHttpRequest-based JavaScript code; instead, it outputs ajaxCall with each JavaScript event handler and a corresponding PHP event handler where you put your PHP event handling code. For more information on ajaxCall, refer to VCL for PHP documentation as this approach is beyond the scope of these notes.
Think client-server
Like a client-server application, a Web app's code is running on two different computers. The PHP code and any PHP extensions you develop are running on a Web server and JavaScript code is running in the user's browser. Furthermore, the server-side PHP generates and sends much of the JavaScript that the browser runs. Ajax techniques are used to communicate between the browser and the Web server.
Don't confuse the two places where code is running. Although your main PHP form may contains a mix of PHP and embedded JavaScript, the PHP only runs on the server and the JavaScript only runs in the browser. You may find it easier to put mostly just JavaScript event code in your main PHP form, along with any one-time PHP code in the form's PHP Create handler. The rest of your app can then be made up of separate PHP files that are run via Ajax or some other technique.
One implication of this client-server split you may find confusing is that the names of the VCL for PHP component properties differ somewhat from the JavaScript DOM and qooxdoo object properties. For example, a reference to the main form's Caption in PHP would look like this:
$this->MainForm_Window->Caption
Whereas a reference to it in JavaScript would look like this:
MainForm_Window.getCaption()