|
|
||||||||||||||||||
|
|
||||||||||||||||||
![]() |
![]() |
Issue 7 - Revision 7 / May 19, 2004
|
|||
|
PHParser/PHPGateway Enabling PHP in Zope - - - - - - - - - - - - By Samuel Sotillo | April2, 2004
PHP code can be integrated into Zope applications without significant adjustments. It might be possible as well quickly to incorporate legacy PHP applications and code into new Zope-based applications or upgrades. ConsThe product's sourcecode must be modified for installation. PHP sourcecode must be altered so that the PHP include/require functions can be dealt with. For include_once/require_once functions a search mechanism must be implemented. I tested it with Plone and it worked but since the documentation warns one to be careful and Plone is a rather complex product, portability cannot be guaranteed. Summary PHParser/PHPGateway is a Zope product that allows zopists to use their PHP scripts under Zope and Plone. It consists of two objects: a DTML-based object and a folder-like object. It accesses PHP content through CGI allowing Zope to be used as a sort of virtual server. IntroductionThe present review examines an example of the intersection of two technologies, PHP and ZOPE, which may be considered rivals but which, in many circumstances, are actually complementary. The product we are reviewing is PHParser/PHPGateway. Initially developed by Maik Jablonski, PHParser was extended by Hewei and then merged with PHPGateway. In its current version, PHParser/PHPGateway allows both zopists and PHP programmers to get the best of these two competing Web technologies at a minimum price.
Prerequisites and Installation Tips PHParser/PHPGateway requires PHP 4.0 or up. Because—according to the documentation—neither the Apache module nor the PHP CLI available with PHP 4.3.x “will work,” PHP must be compiled with the “--enable-force-cgi-redirect” option. For more details about how to compile and set up the interpreter, we recommend that our readers consult the PHParser/PHPGateway documentation available at http://zope.org/Members/hewei/PHParser/. The PHParser/PHPGateway product is available as a compressed TAR file — see sidebar to find out how to download the package. Readers working in Windows environments may use an archiving tool like Winzip to unpack the file — while those working in Linux environments may use the standard GNU tar utility. The most important tip to remember is to unpack the file into Zope's Products/ folder. For instance, with Linux you may proceed as follows:
The Before restarting Zope, we need to modify our source file to be sure that PHParser knows where to find the PHP CGI binaries. An explanation as to how to do this may be found in the documentation mentioned above.
Once everything has been double-checked, we must restart Zope. The product description should appear in the
Additionally, if everything has gone well, we should have two new items listed in the Add Product list: the PHParser and PHPGateway objects. OK! Now, we are ready to start using the product. UsageThe two main components of PHParser/PHPGateway work in different ways. The first component, PHParser, behaves like a DTML document. It should be used when all we need to integrate into our Zope application are independent pieces of PHP code. For instance, let's suppose we have a piece of PHP code that can generate bar charts as JPEG images. Now, let's suppose that all we need is the output — i.e., the images themselves. We can import our PHP code into Zope by clicking onto the Add Product list and selecting the PHParser object. A new View like the one shown in Figure 2 should then appear.
Figure 3 below depicts an example of a piece of PHP code imported into Zope. This piece of code can generate a bar chart satisfying certain parameter values — of course, for economy's sake, we will not explain the details of this code. The important point here is that our legacy code has been translated into the standard look of a DTML object — that it has, so to speak, been translated into a ZODB object. This means that we can use it the same way we use any other DTML document — for example, we can pass values to it, we can call other objects or scripts from it, and so on.
Another possibility, which is particularly interesting for our case, is that we can invoke this DTML document from inside an HTML tag such as an
What happens here is that the DTML object
The second component, PHPGateway, works in a very different way. First of all, it is a “folder-like object.” It is useful when what we need to integrate into Zope is a whole site or a complete directory structure. PHPGateway does not translate our PHP code into ZODB objects. On the contrary, all that PHPGateway does is define a pointer to the location in the file system where the code is located. On demand, every PHP file within such a directory structure is passed to PHP CGI — without DTML rendering — as needed. Figure 6 shows the Add PHPGateway View. The only parameter that needs explanation is docroot. It is the path of the directory structure our PHP files are located in. It is important to note that such a directory must contain a recognizable index-type file — that is, that within the docroot folder there must be a file named either index.php or default.php.
Once created, we can test our new PHPGateway folder by using its View option. Figure 7 shows the result of our sample: a bar chart generated with PHP's Panachart library — for more information about this excellent library go to http://www.panacode.com/.
Another interesting advantage of PHPGateway is that Zope can publish its content as a virtual hostname. For instance, Zope published our test site as
One interesting property of PHP is its ability to include other PHP files into a single source. PHP has different ways of doing this -— two very common ways are the <?php // include file “myfile.php” include(“myfile.php”); ... ?>
A similar approach must be used with either the
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ZopeMag is committed to bringing you the best in Zope Documentation. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
Reproduction of material from any of ZopeMag's pages without prior written permission is strictly prohibited. Copyright 2003 - 2005 ZopeMag |
|