API16

JDispatcher/register

From Joomla! Documentation

< API16:JDispatcher
Revision as of 17:47, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Registers an event handler to the event dispatcher <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JDispatcher/register|Edit Descri...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

[Edit Descripton]

Template:Description:JDispatcher/register

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

[Edit See Also] Template:SeeAlso:JDispatcher/register

Examples[edit]

<CodeExamplesForm />