Login / Status
developer.Resource
Home . Documentation . Document Library . Extension Manuals
Sponsors
hosted by punkt.deTYPO3 and Open Source Magazine

1.3. Section 1 - Internal

About this section

Functions for the initialization of the class.

Those functions are the core of this API. Except the class constructor, they are all reserved for internal use.

tx_apimacmade

Class constructor.

This function can't be called by t3lib_div::makeInstance, since it needs the parent object to be passed as an argument. Sorry about that.

When you call the constructor, do not forget to set the $apimacmade_version class variable, as it will be used for version checking. Read the example below to find out more.

Parameters

Parameter:

Default value:

Description:

&$pObj

The parent object

Return

Void.

Example

Heres how to use this API in your own extensions. First, you'll need to include the API class in your extension (line 5). This is done like this (all of following example are in a frontend plugin context, but the procedure is the same for every development context):

1:

2:

3:

4:

5:

6:

7:

// Typo3 FE plugin class

require_once(PATH_tslib.'class.tslib_pibase.php');

// API class

require_once(t3lib_extMgm::extPath('api_macmade').'class.tx_apimacmade.php');

class tx_myextension_pi1 extends tslib_pibase {

Then you need to define a class variable (line 13):

1:

2:

3:

4:

5:

6:

7:

8:

9:

10:

11:

12:

13:

class tx_myextension_pi1 extends tslib_pibase {

// Same as class name

var $prefixId = 'tx_myextension_pi1';

// Path to this script relative to the extension dir

var $scriptRelPath = 'pi1/class.tx_myextension_pi1.php';

// The extension key

var $extKey = 'myextension';

// API version

var $apimacmade_version = 1.0;

It's used to check the version of the API. Let's say you have made an extension which uses the version 1.1 of this API, and that you have set the version variable consequently. If a user try to use your extension with an older version of the API, he may get some problems, as some functions may not be present. So with this variable, the user will just get a page saying he should upgrade to the required version (1.1 in that case). It's a way to protect your work from errors dues to an old version.

The last step is to instantiate the API class. You can't do that by calling t3lib_div::makeInstance, as the class constructor needs an argument to be passed. So here's how we do this (line 4):

1:

2:

3:

4:

function main($content,$conf) {

// New instance of the API

$this->api = new tx_apimacmade($this);

Most often, it's a good idea to set the API object as a class variable, like in this example, to allow you to use API function from any of your functions. The parameter of the constructor must be always be $this. It will allow the API to reach your own variables by itself, and to use all of the Typo3 core functions available in your context.

Then, you're done. You can use the function you need, just like that, for example:

1:

$this->api->debug('Hello World!');

In this manual, we are going to use $this->api for the API object, in the examples. You're of course free to name that object as you want.

versionError

Produce a version error message.

This function produce the error message if the version of the API is too old.

Parameters

Parameter:

Default value:

Description:

$version
false

The required version of the API

Return

An HTML page with the error message.

errorMsg

Produce an error message.

This function is used to produce an error message, if another function report a problem, often caused by bad argument types.

Parameters

Parameter:

Default value:

Description:

$function

The ID/name of the function

Return

Void.