beforeHandleRequest Application Delegate Class Method
Return to Application Delegate Class
Synopsis
The beforeHandleRequest method is a very useful hook that can be implemented in an Application Delegate Class to perform some processing before every request.
This hook is called after user authentication is taken care of, but before control has been passed to the specific action. This means that it is possible to do things such as change the current action or adjust query parameters depending on various factors.
Example Uses
- To require users to fill agree to license terms before they can visit particular parts of the application.
- To implement custom logging functionality to record user actions
- To change the default action for some or all tables.
- To automatically create user accounts in some cases.
- To change query parameters (e.g. default sorting etc…).
Examples
Example 1: Changing the default action for a particular table
class conf_ApplicationDelegate {
function beforeHandleRequest(){
$app = Dataface_Application::getInstance();
$query =& $app->getQuery();
// Make sure you assign by reference (i.e. =& )
// for this if you want to make changes to the query
if ( $query['-table'] == 'dashboard' and @$app->_conf['using_default_action'] ){
$query['-action'] = 'my_default_action';
}
}
}
In the above example, we make use of the Application configuration variable using_default_action to find out if the request is using the default action. This flag is set by Xataface if the user hasn’t explicitly declared the action in the URL (i.e. -action has not explicitly been set).
See Also
- Application Delegate Class
- Dataface_Application API Docs
- Xataface URL Conventions
- Customizing Theme Based on IP Address - Article containing an example of using beforeHandleRequest hook.
var disqus_identifier = ‘xataface.com/wiki/beforeHandleRequest’; (function() { var dsq = document.createElement(‘script’); dsq.type = ‘text/javascript’; dsq.async = true; dsq.src = ‘http://xataface.disqus.com/embed.js’; (document.getElementsByTagName(‘head’)[0] || document.getElementsByTagName(‘body’)[0]).appendChild(dsq); })(); blog comments powered by Disqus
//<![CDATA[ (function() { var links = document.getElementsByTagName(‘a’); var query = ‘?’; for(var i = 0; i < links.length; i++) { if(links[i].href.indexOf(‘#disqus_thread’) >= 0) { query += ‘url’ + i + ‘=’ + encodeURIComponent(links[i].href) + ‘&’; } } document.write(‘