<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>beforeHandleRequest[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D107&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Wed, 22 May 2013 01:46:09 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>beforeHandleRequest</title>
            <link>http://www.xataface.com/wiki/beforeHandleRequest</link>
            <description>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page name&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;beforeHandleRequest&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page id&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;107&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page title&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;beforeHandleRequest Application Delegate Class Method&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Content&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;&lt;p&gt;Return to &lt;a href=&quot;/wiki/Application_Delegate_Class&quot;&gt;Application Delegate Class&lt;/a&gt;&lt;/p&gt;

&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tr&gt;&lt;td&gt;
&lt;div id=&quot;toc&quot;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc0&quot;&gt;Synopsis&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc1&quot;&gt;Example Uses&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 0em;&quot;&gt;&lt;a href=&quot;#toc2&quot;&gt;Examples&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc3&quot;&gt;Example 1: Changing the default action for a particular table&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 0em;&quot;&gt;&lt;a href=&quot;#toc4&quot;&gt;See Also&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;


&lt;h3 id=&quot;toc0&quot;&gt;Synopsis&lt;/h3&gt;
&lt;p&gt;The beforeHandleRequest method is a very useful hook that can be implemented in an &lt;a href=&quot;/wiki/Application_Delegate_Class&quot;&gt;Application Delegate Class&lt;/a&gt; to perform some processing before every request.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;


&lt;h3 id=&quot;toc1&quot;&gt;Example Uses&lt;/h3&gt;
&lt;ul&gt;
    &lt;li&gt; To require users to fill agree to license terms before they can visit particular parts of the application.&lt;/li&gt;
    &lt;li&gt; To implement custom logging functionality to record user actions&lt;/li&gt;
    &lt;li&gt; To change the default action for some or all tables.&lt;/li&gt;
    &lt;li&gt; To automatically create user accounts in some cases.&lt;/li&gt;
    &lt;li&gt; To change query parameters (e.g. default sorting etc...).&lt;/li&gt;
&lt;/ul&gt;


&lt;h2 id=&quot;toc2&quot;&gt;Examples&lt;/h2&gt;

&lt;h3 id=&quot;toc3&quot;&gt;Example 1: Changing the default action for a particular table&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;class conf_ApplicationDelegate {
    
    function beforeHandleRequest(){
        $app = Dataface_Application::getInstance();
        $query =&amp;amp; $app-&amp;gt;getQuery();
            // Make sure you assign by reference (i.e. =&amp;amp; )
            // for this if you want to make changes to the query
            
        if ( $query['-table'] == 'dashboard' and $app-&amp;gt;_conf['using_default_action'] ){
            $query['-action'] = 'my_default_action';
        }
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the above example, we make use of the Application configuration variable using_default_action&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=using_default_action&quot;&gt;?&lt;/a&gt; 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).&lt;/p&gt;


&lt;h2 id=&quot;toc4&quot;&gt;See Also&lt;/h2&gt;
&lt;ul&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/Application_Delegate_Class&quot;&gt;Application Delegate Class&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;http://dataface.weblite.ca/Dataface_Application&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;Dataface_Application API Docs&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt; Xataface URL Conventions&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=Xataface_URL_Conventions&quot;&gt;?&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt; &lt;strong&gt;&lt;a href=&quot;/wiki/Customizing_Theme_Based_on_IP_Address&quot;&gt;Customizing Theme Based on IP Address&lt;/a&gt;&lt;/strong&gt; - Article containing an example of using beforeHandleRequest hook.&lt;/li&gt;
&lt;/ul&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Keywords&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;beforeHandleRequest, Application Delegate&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Language&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;en&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description>
            <author>beforeHandleRequest</author>
        </item>
    </channel>
</rss>
