API15

JDispatcher/register

From Joomla! Documentation

< API15:JDispatcher
Revision as of 19:29, 24 March 2017 by JoomlaWikiBot (talk | contribs) (preparing for archive only)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API15" 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 edit link to red link >]

<! 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]

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 edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]