API16

JDispatcher/register

From Joomla! Documentation

< API16:JDispatcher

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Registers an event handler to the event dispatcher


<! removed transcluded page call, red link never existed >

Syntax[edit]

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[edit]

void

Defined in[edit]

libraries/joomla/event/dispatcher.php

Importing[edit]

jimport( 'joomla.event.dispatcher' );

Source Body[edit]

public 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);
        }
}


<! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]