Elgg  Version 6.0
Functions
pagehandler.php File Reference

Go to the source code of this file.

Functions

 elgg_register_route (string $name, array $params=[])
 Elgg page handler functions. More...
 
 elgg_unregister_route (string $name)
 Unregister a route by its name. More...
 
 elgg_get_route (string $name)
 Get a registered route by it's name. More...
 
 elgg_get_route_for_url (string $url)
 Find a registered route based on an url/path. More...
 
 elgg_get_current_route ()
 Get the route for the current request. More...
 
 elgg_get_current_route_name ()
 Get the route name for the current request. More...
 
 elgg_route_exists (string $name)
 Check if a route is registered. More...
 
 elgg_get_current_url ()
 Returns the current page's complete URL. More...
 
 elgg_generate_url (string $name, array $parameters=[])
 Generate a URL for named route. More...
 
 elgg_generate_entity_url (ElggEntity $entity, string $resource= 'view', string $subresource=null, array $parameters=[])
 Generate entity URL from a named route. More...
 
 elgg_generate_action_url (string $action, array $query=[], bool $add_csrf_tokens=true)
 Generate an action URL. More...
 
 elgg_ok_response ($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
 Prepares a successful response to be returned by a page or an action handler. More...
 
 elgg_error_response (string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
 Prepare an error response to be returned by a page or an action handler. More...
 
 elgg_redirect_response (string $forward_url=REFERRER, int $status_code=ELGG_HTTP_FOUND, bool $secure_forward_url=true)
 Prepare a silent redirect response to be returned by a page or an action handler. More...
 
 elgg_download_response (string $content, string $filename= '', bool $inline=false, array $headers=[])
 Prepare a download response. More...
 

Function Documentation

elgg_download_response ( string  $content,
string  $filename = '',
bool  $inline = false,
array  $headers = [] 
)

Prepare a download response.

Parameters
string$contentThe content of the download
string$filenameThe filename when downloaded
bool$inlineIs this an inline download (default: false, determines the 'Content-Disposition' header)
array$headers(optional) additional headers for the response
Returns
Since
5.0

Definition at line 285 of file pagehandler.php.

elgg_error_response ( string|array  $message = '',
string  $forward_url = REFERRER,
int  $status_code = ELGG_HTTP_BAD_REQUEST 
)

Prepare an error response to be returned by a page or an action handler.

Parameters
string | array$messageError message Can be used by handlers to display an error message For certain requests this error message will also be used as the response body
string$forward_urlURL to redirect the client to Can be used by handlers to redirect the client on non-ajax requests
int$status_codeHTTP status code Status code of the HTTP response
Returns

Definition at line 245 of file pagehandler.php.

elgg_generate_action_url ( string  $action,
array  $query = [],
bool  $add_csrf_tokens = true 
)

Generate an action URL.

Parameters
string$actionAction name
array$queryQuery elements
bool$add_csrf_tokensAdd tokens
Returns
string
Examples:
/root/Elgg/engine/classes/Elgg/FormsService.php.

Definition at line 197 of file pagehandler.php.

elgg_generate_entity_url ( ElggEntity  $entity,
string  $resource = 'view',
string  $subresource = null,
array  $parameters = [] 
)

Generate entity URL from a named route.

This function is intended to generate URLs from registered named routes that depend on entity type and subtype. It will first try to detect routes that contain both type and subtype in the name, and will then fallback to route names without the subtype, e.g. 'view:object:blog:attachments' and 'view:object:attachments'

Route segments will be automatically resolved from entity attributes and metadata, so given the path /blog/view/{guid}/{title}/{status} the path will be be resolved from entity guid, URL-friendly title and status metadata.

Parameters that do not have matching segment names in the route path, will be added to the URL as query elements.

Parameters
ElggEntity$entityEntity
string$resourceResource name
string$subresourceSubresource name
array$parametersURL query elements
Returns
string|null

Definition at line 159 of file pagehandler.php.

elgg_generate_url ( string  $name,
array  $parameters = [] 
)

Generate a URL for named route.

Parameters
string$nameRoute name
array$parametersParameters
Returns
string|null

Definition at line 133 of file pagehandler.php.

elgg_get_current_route ( )

Get the route for the current request.

Returns
|null
Since
4.0

Definition at line 88 of file pagehandler.php.

elgg_get_current_route_name ( )

Get the route name for the current request.

Returns
string Will be an empty string if no current route is found
Since
4.1

Definition at line 98 of file pagehandler.php.

elgg_get_current_url ( )

Returns the current page's complete URL.

Returns
string
Since
4.3

Definition at line 121 of file pagehandler.php.

elgg_get_route ( string  $name)

Get a registered route by it's name.

Parameters
string$namethe route name
Returns
|null
Since
4.0

Definition at line 50 of file pagehandler.php.

elgg_get_route_for_url ( string  $url)

Find a registered route based on an url/path.

Parameters
string$urlthe full url or an url path to find a route for
Returns
|null
Since
4.1

Definition at line 62 of file pagehandler.php.

elgg_ok_response (   $content = '',
string|array  $message = '',
string  $forward_url = null,
int  $status_code = ELGG_HTTP_OK 
)

Prepares a successful response to be returned by a page or an action handler.

Parameters
mixed$contentResponse content In page handlers, response content should contain an HTML string In action handlers, response content can contain either a JSON string or an array of data
string | array$messageSystem message visible to the client Can be used by handlers to display a system message
string$forward_urlForward URL Can be used by handlers to redirect the client on non-ajax requests
int$status_codeHTTP status code Status code of the HTTP response (defaults to 200)
Returns

Definition at line 224 of file pagehandler.php.

elgg_redirect_response ( string  $forward_url = REFERRER,
int  $status_code = ELGG_HTTP_FOUND,
bool  $secure_forward_url = true 
)

Prepare a silent redirect response to be returned by a page or an action handler.

Parameters
string$forward_urlRedirection URL Relative or absolute URL to redirect the client to
int$status_codeHTTP status code Status code of the HTTP response Note that the Router and AJAX API will treat these responses as redirection in spite of the HTTP code assigned Note that non-redirection HTTP codes will throw an exception
bool$secure_forward_urlDetermines if the forward url needs to be secure
Returns

Definition at line 270 of file pagehandler.php.

elgg_register_route ( string  $name,
array  $params = [] 
)

Elgg page handler functions.

Register a new route

Route paths can contain wildcard segments, i.e. /blog/owner/{username} To make a certain wildcard segment optional, add ? to its name, i.e. /blog/owner/{username?}

Wildcard requirements for common named variables such as 'guid' and 'username' will be set automatically.

Parameters
string$nameUnique route name This name can later be used to generate route URLs
array$paramsRoute parameters
  • path : path of the route
  • resource : name of the resource view
  • defaults : default values of wildcard segments
  • requirements : regex patterns for wildcard segment requirements
  • methods : HTTP methods
Returns

Definition at line 27 of file pagehandler.php.

elgg_route_exists ( string  $name)

Check if a route is registered.

Parameters
string$nameroute name
Returns
bool
Since
4.0

Definition at line 111 of file pagehandler.php.

elgg_unregister_route ( string  $name)

Unregister a route by its name.

Parameters
string$nameName of the route
Returns
void

Definition at line 38 of file pagehandler.php.