Path

ez.no / exponential / documentation / customization / tips & tricks / how can i use my own php script inside ezp?


How can I use my own php script inside eZp?

These documentation pages are no longer maintained. Please visit the new documentation site.

eZp can't use PHP code inside templates, however there is a way to use your own PHP scripts in a template:

How to include your own PHP script in eZp

First include your PHP script inside eZp's index.php. Let's assume your PHP script is divided in three, input-handling, data-handling and output generation.

Input handling

eZp corrects all $GLOBALS, _GET and _POST for magic quotes for safety reasons. More info in ./lib/ezutils/classes/ezsys.php

Execution of the script

Just echo-ing the variables is not enough! Since eZp is run from one script source, index.php, you'll have to add a way to execute a script based on the URL tags.

Data handling

Data handling of your scripts should be no problem at all, except when both your script and eZp use the same variable names. If that's the case, start renaming of your scripts variables.

Output handling

The trick is to put all output of your script in a $variable. Some scripts use a (customized) template engine and there might be an option for output into a $variable instead of the screen. This is achieved with output buffering, for more information see ob_start -- Turn on output buffering.

ob_start(); # start output buffering

# put your output script here

$variable = ob_get_contents(); # store the output in $variable

ob_end_clean(); # clean output buffering

All output is now in $variable !

The last step is to include this into your eZp template:

{$variable}

Notes:

Make sure the output of your script is XML-ready and does not contain HTML headers like , or
Ezphpcreator for PHP inclusion?

Subversion 2019 contains a file calles ezphpcreator.php in ./lib/ezutils/classes. Comments or SDK references are not included but it looks like a PHP implementation by eZp!

Comments

Another solution to using PHP inside templates

Contents

Customization

Access control
Exponential API Documentation
Content structure
Custom design
Components
Tips & Tricks
    Debugging templates
    Javascript in templates
    Fetching current user
    Showing related objects
    Show which templates are used
    Fetching the ID of the parent
    One Article Folder
    Creating tree menus
    How can I use my own php script insid...
    Hiding attribute content
    Splitting an article over several pages
    Accessing section id in pagelayout
    List articles in folder
    Creating nice URLs
    Alt tag on images
    Improve the pagelayout.tpl
    Clean HTML tags
    Insert javascript call inside ezpub d...
    3rd party applications
    Fetch Function examples
    Display more than 15 items on your co...
    Including PHP files in templates
    Redirecting after content publishing
    HowTo see if article has an image
    Date and Time Formats
    Forms processing example: store user...
    Adjust Timezone
    Adding a Remove Button/Image
    Find the age in years for an object
    Editing, creating and removing conten...
    Indexing binary files with IFilters o...
Troubleshooting


Created

30/04/2003
12:50:16 pm
by Niklas Gunnäs

Last updated

04/07/2003
5:10:21 pm
by Bård Farstad

Authors

Niklas Gunnäs
Bård Farstad



This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.