Actions

API15

JDispatcher/register

From Joomla! Documentation

< API15:JDispatcher
Revision as of 17:20, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Registers an event handler to the event dispatcher

[Edit Descripton]

Description:JDispatcher/register

Syntax

register($event, $handler)
Parameter Name Default Value Description
$event $event Name of the event to register handler for
$handler $handler Name of the event handler

Returns

void

Defined in

libraries/joomla/event/dispatcher.php

Importing

jimport( 'joomla.event.dispatcher' );

Source Body

function register($event, $handler)
{
        // Are we dealing with a class or function type handler?
        if (function_exists($handler))
        {
                // Ok, function type event handler... lets attach it.
                $method = array ('event' => $event, 'handler' => $handler);
                $this->attach($method);
        }
        elseif (class_exists($handler))
        {
                 //Ok, class type event handler... lets instantiate and attach it.
                $this->attach(new $handler($this));
        }
        else
        {
                JError::raiseWarning('SOME_ERROR_CODE', 'JDispatcher::register: Event handler not recognized.', 'Handler: '.$handler );
        }
}

[Edit See Also] SeeAlso:JDispatcher/register

Examples

<CodeExamplesForm />