Page handlers
Page handlers manage the response to a request. The response can be a web page, RSS feed, or any number of other output formats. Because Elgg uses the MVC pattern, the same handler is used for different response formats; only the views change.
A page handler is registered by mapping a URL identifier to a function, as follows:
elgg_register_page_handler('blog', 'blog_page_handler');
This handler function is called when a request is made to a URL starting with /blog/
.
The handler function receives an array of the segments of the URL. This array is used to further route the request in the handler. The handler function can process requests in the function itself, include page handling scripts, or use a page handler class. Developers can select the approach that best matches the job and their programming style.
Page handlers include both controller and view code and work like the following:
Access any user input through
get_input()
.Pull data from the model related to the request.
Push the data into the views system for rendering.
Send output to the requester using
elgg_view_page()
.
Code location
Core page handlers: directories in /pages/
Example of script-based page handling in a plugin: bookmarks plugin
Example of function-based page handling in a plugin: blog plugin