Integrating PHP applications in Plone

How to use PHPParser to display content from an external PHP application inside Plone.

Here are the steps to follow:

  • Install PHParser
  • From the ZMI, add a PHParser item that references each of your existing PHP page. For instance, if one of your PHP pages is located in /myphp/index.php, your PHParser item will contain:

    <?php
    include="/myphp/index.php";
    ?>
  • In the ZMI, create a Page template for each PHP file. Each Page template will reference a PHParser item. For instance, if you have called your PHParser item mainPage:

    <html metal:use-macro="here/main_template/macros/master">
    <head>
    </head>
    <body>

    <tal:block metal:fill-slot="content" content="structure here/mainPage">
    </tal:block>
    </body>
    </html>
  • You need the keyword structure if your PHP file generates HTML. If your PHP file generates plain text, you can simply use: content="here/mainPage".


Thanks to Wei He, creator of PHParser, for his help.


    A more generic way

    If you have many php files this is very tedious. There is in fact a more generic way, using one single template for all:

    • Create the template in your portal_skins/custom folder instead, call it php_view and modify it slightly
    • Replace <tal:block metal:fill-slot="content" content="structure here/mainPage">
    • With <tal:block metal:fill-slot="content" content="structure here">
    • Then you access all your PHParser pages with myphppage/php_view

    Note that you must consider security if you take the generic approach: remember that all your PHP files in that particular folder will be accessible.


    How to make PHParser work with Plone 2.5

    Posted by Stefan H. Holek at Aug 15, 2006 02:27 PM
    To make PHParser work with Plone 2.5 you need to make PHParser items five:traversable. The simplest way is to edit CMFPlone/configure.zcml and add the following line:

      <five:traversable class="Products.PHParser.PHParser.PHParser" />

    Then restart Zope.

    D'oh

    Posted by Stefan H. Holek at Aug 15, 2006 02:30 PM
    Damn HTML transformations...

    &lt;five:traversable class="Products.PHParser.PHParser.PHParser" /&gt;