Elgg\Http\Request::getUrlSegments PHP Method

getUrlSegments() public method

Get the Elgg URL segments
public getUrlSegments ( boolean $raw = false ) : string[]
$raw boolean If true, the segments will not be HTML escaped
return string[]
    public function getUrlSegments($raw = false)
    {
        $path = trim($this->query->get(Application::GET_PATH_KEY), '/');
        if (!$raw) {
            $path = htmlspecialchars($path, ENT_QUOTES, 'UTF-8');
        }
        if (!$path) {
            return array();
        }
        return explode('/', $path);
    }

Usage Example

Example #1
0
 /**
  * Routes the request to a registered page handler
  *
  * This function triggers a plugin hook `'route', $identifier` so that plugins can
  * modify the routing or handle a request.
  *
  * @param \Elgg\Http\Request $request The request to handle.
  * @return boolean Whether the request was routed successfully.
  * @access private
  */
 public function route(\Elgg\Http\Request $request)
 {
     $segments = $request->getUrlSegments();
     if ($segments) {
         $identifier = array_shift($segments);
     } else {
         $identifier = '';
         // this plugin hook is deprecated. Use elgg_register_page_handler()
         // to register for the '' (empty string) handler.
         // allow plugins to override the front page (return true to indicate
         // that the front page has been served)
         $result = _elgg_services()->hooks->trigger('index', 'system', null, false);
         if ($result === true) {
             elgg_deprecated_notice("The 'index', 'system' plugin has been deprecated. See elgg_front_page_handler()", 1.9);
             exit;
         }
     }
     // return false to stop processing the request (because you handled it)
     // return a new $result array if you want to route the request differently
     $result = array('identifier' => $identifier, 'handler' => $identifier, 'segments' => $segments);
     if ($this->timer) {
         $this->timer->begin(['build page']);
     }
     $result = $this->hooks->trigger('route', $identifier, $result, $result);
     if ($result === false) {
         return true;
     }
     if ($identifier != $result['identifier']) {
         $identifier = $result['identifier'];
     } else {
         if ($identifier != $result['handler']) {
             $identifier = $result['handler'];
         }
     }
     $segments = $result['segments'];
     $handled = false;
     ob_start();
     if (isset($this->handlers[$identifier]) && is_callable($this->handlers[$identifier])) {
         $function = $this->handlers[$identifier];
         $handled = call_user_func($function, $segments, $identifier);
     }
     $output = ob_get_clean();
     $ajax_api = _elgg_services()->ajax;
     if ($ajax_api->isReady()) {
         $path = implode('/', $request->getUrlSegments());
         $ajax_api->respondFromOutput($output, "path:{$path}");
         return true;
     }
     echo $output;
     return $handled || headers_sent();
 }
All Usage Examples Of Elgg\Http\Request::getUrlSegments