DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

EXT: Page PHP Content

Author:Kasper Skårhøj
Created:2002-11-01T00:32:00
Changed:2003-09-26T18:56:45
Author:Gary
Email:gniemcew@yahoo.com
Info 3:
Info 4:

EXT: Page PHP Content

Extension Key: page_php_content

Copyright 2000-2002, Gary, <gniemcew@yahoo.com>

This document is published under the Open Content License

available from http://www.opencontent.org/opl.shtml

The content of this document is related to TYPO3

- a GNU/GPL CMS/Framework available from www.typo3.com

Table of Contents

EXT: Page PHP Content 1

Introduction 1

What does it do? 1

Screenshots 1

Users manual 2

Adding PHP Code To a Page 2

PHP Code Tips 2

Introduction

What does it do?

Page PHP Content is a tiny extension that adds a new “PHP Script”page content type to the TYPO3 backend. It allows you to enter a piece of PHP script as a page content element the same way as you would add “Text”, “Text w/Image”, or “Insert Plugin”.

The main goal of the extensionis to provide a way to include a PHP code snippet on any page (on page-to-page and element-to-element basis) without having to go through writing a separate extension in itself, or setting up parseFunc tags with externally included PHP files - a lot of PHP files to create and a lot of housekeeping if you have, say, 30 separate small pieces of PHP all over the site in various pages.

Instead, you add a “PHP Script” content element to a page, enter (or copy and paste) the code in the backend text editor, and hit save. Each PHP code segment is stored in mySQL TYPO3 database (no external files needed). Your PHP code will be executed non-cached and its printt, echo, etc. output (if any) captured, buffered, and returned to TYPO3 as a content element as a part of the whole page.

Screenshots

img-1

That's all there is to it: create a new content element of the “PHP Script” type, enter the PHP code and it would appear on a page (no class definition required), and save it. The output will appear on our page.

Users manual

Adding PHP Code To a Page

Download the extension from the typo3.org repository and load it. Agree to clear cache.

No configuration of any kind is necessary.

Select a page in your page tree using backend Web >> Page >> [page name]command.

Click on Create Page Content,select any type (say, Text), and select “PHP Script” from the “Type:” drop-down.

Optionally, enter a description for the PHP code in the Headerfield. It will NOT be displayed on the page, this is just a “note to self” kind of thing.

Enter the relevant PHP code in the “PHP Code” section. Follow standard guidelines for adding PHP code to an HTML page.

Save the page, and view it – the code output will appear it in the appropriate place.

PHP Code Tips

This extension is using PHP eval()function and output buffering. For more details and information about how it works, see PHP core documentation.

Generally speaking, include the PHP start and end tags. Depending on your PHP version, you might not even have to.

Since you cannot “return” anything from a page, use the standard PHP print(), echo(), etc. function to standard output to build your page. Whatever you output in the course of running your code will be captured and returned to TYPO3 as regular string-based HTML content.

Note that since your PHP code is running in the “index.php” context, its current working directory and inclusion path will dependon where your TYPO3 index.php file is, and plan accordingly. You can easily manipulate PHP include paths using set_include_path (). Make sure to “undo” any changes with restore_include_path (), otherwise TYPO3 index.php will probably complain.

Note that your PHP code will run as a non-cached USER_INT object, which means that it will be executed every time a page is requested (other page pieces may or may not load from the page cache). If you have some large or CPU-intensive PHP chunk, better make up a separate cached extension.

Your PHP code gets stored in TYPO3 mySQL backend, tt_content table, tx_pagephpcontent_php_code field (in other words, the tt_content table gets so called “extended”). If you badly need to change this extension to cache'able, change the following in the extension ext_localconf.php : t3lib_extMgm::addPItoST43($_EXTKEY,"pi1/c lass.tx_pagephpcontent_pi1.php","_pi1","CType",0); to include 1 instead of 0 as the last argument.

img-2 EXT: Page PHP Content - 2