Elgg\Router::registerPageHandler PHP Method

registerPageHandler() public method

Register a function that gets called when the first part of a URL is equal to the identifier.
public registerPageHandler ( string $identifier, string $function ) : boolean
$identifier string The page type to handle
$function string Your function name
return boolean Depending on success
    public function registerPageHandler($identifier, $function)
    {
        if (is_callable($function, true)) {
            $this->handlers[$identifier] = $function;
            return true;
        }
        return false;
    }

Usage Example

Example #1
0
 /**
  * 1. Register a page handler for `/foo`
  * 2. Register a plugin hook that uses the "handler" result param
  *    to route all `/bar/*` requests to the `/foo` handler.
  * 3. Route a request for a `/bar` page.
  * 4. Check that the `/foo` handler was called.
  */
 function testRouteSupportsSettingHandlerInHookResultForBackwardsCompatibility()
 {
     $this->router->registerPageHandler('foo', array($this, 'foo_page_handler'));
     $this->hooks->registerHandler('route', 'bar', array($this, 'bar_route_handler'));
     $query = http_build_query(array('__elgg_uri' => 'bar/baz'));
     ob_start();
     $this->router->route(\Elgg\Http\Request::create("http://localhost/?{$query}"));
     ob_end_clean();
     $this->assertEquals(1, $this->fooHandlerCalls);
 }
All Usage Examples Of Elgg\Router::registerPageHandler