Register a new API

API configurations can be registered by creating a new node in the global $GLOBALS['PCT_CUSTOMCATALOG']['API'] array. Each API should have a unique key.

.../config/config.php

<?php

/** 
 * Register new API 
 */
$GLOBALS['PCT_CUSTOMCATALOG']['API']['myApi'] = array
(
    'label' => &$GLOBALS['TL_LANG']['PCT_CUSTOMCATALOG']['API']['myApi'],
    'class' => 'MyCustomCatalogApi', // The default class if no callbacks for modes have been registered
);

Now the API will be available in the API selection.


Options [key]

  • array "label"

    Translations array (0=>title, 1=>description)

  • string "class"

    The main API php class

  • string "path"

    Path to a submodule folder nested inside a basic Contao module structure

  • array "modes"

    Register custom API modes

  • array "key"

    Registration array for backend pages (available keys: run, summary)

    array('run'=> array(Myclass, MyCallback) );


* Register classes

Register the classes using Contao's autoloader.

.../config/autoload.php

<?php

/**
 * Register the classes 
 */
ClassLoader::addClasses(array
(
    'MyCustomCatalogApi' => 'system/modules/pct_customcatalog_api_examples/MyCustomCatalogApi.php'
));

* Autoloading requirements

Since the API relies on the CustomCatalog extension pct_customelements_plugin_customcatalog, tell Contao to load CC before this extension (requirement).

.../config/autoload.ini

;;
; List modules which are required to be loaded beforehand
;;
requires[] = "core"
requires[] = "pct_customelements_plugin_customcatalog"

;;
; Configure what you want the autoload creator to register
;;
register_namespaces = true
register_classes = true
register_templates = true

*This step can be done with the Contao Autoload-Creator once the file structure exists and class files contain valid php classes.

results matching ""

    No results matching ""