![]() |
Xataface 2.0
Xataface Application Framework
|
The main Application object that handles requests and response. More...
Public Member Functions | |
Request Context | |
Methods and Structures for getting information about the current request context. | |
& | getQuery () |
Returns a reference to the current query object. This is very similar to the $_GET and $_REQUEST globals except this array has been filled in with missing values. | |
& | getQueryParam ($key) |
Returns a query parameter. | |
& | getResultSet () |
Loads the current result set. | |
& | getRecord () |
Gets the current record based on the current query. | |
recordLoaded () | |
Checks is the current record has been loaded yet. | |
& | getAction () |
Gets the settings array for the current action as specified by the -action parameter of the current query. | |
Event Handling | |
Methods for dealing with the dispatch of events. | |
fireEvent ($name, $params=null) | |
Fires an event to all event listeners. | |
registerEventListener ($name, $callback) | |
Registers an event listener to respond to events of a certain type. | |
unregisterEventListener ($name, $callback) | |
Unregisters an event listener. | |
getEventListeners ($name=null) | |
Gets a list of the callbacks that are registered for a given event. | |
Delegate Class | |
Methods for obtaining and working with the delegate class. | |
& | getDelegate () |
Returns a reference to the delegate object for this application. The delegate object can be used to define custom functionality for the application. | |
Permissions | |
Method wrappers for working with permissions. | |
getPermissions ($params=array()) | |
Returns the permissions that are currently available to the user in the current context. If we are in browse mode then permissions are checked against the current record. Otherwise, permissions are checked against the table. | |
checkPermission ($perm) | |
Checks if a permission is granted in the current context. | |
Custom Pages | |
Methods for working with custom pages. These are seldom used and are not the recommended way to make actions in Xataface. | |
& | getCustomPages () |
PHP files located in the 'pages' directory of the site are considered to be custom pages. Passing the GET parameter -action=custom_<pagename> will cause the Application controller to display the page <pagename>.php from the pages directory. This method just returns an array of full paths to the custom pages that are available in the 'pages' directory. | |
getCustomPagePath ($name) | |
Obtains the full path (read for inclusion) of the custom page with name $name. | |
getCustomPageLabel ($name) | |
Obtains the label for a custom page. The label is the same as the name except with capitalization of words and replacement of underscores with spaces. | |
Data Fields | |
const | EX_FAILED_TO_CREATE_SESSION_DIR = 5500 |
$redirectHandler = null | |
An object that implements a method named 'redirect' that is supposed to handle requests to redirect to a new page. This gives an opportunity to suppress redirects or handle them differently inline. This is helpful if you're loading Xataface from a cron script or another application and need to prevent redirects. | |
$rawQuery | |
$prefs | |
User preferences matrix. | |
Languages | |
getLanguage ($langCode) | |
Returns the language associated with a given language code. | |
getLanguageCode ($locale) | |
Returns the Xataface language code for a particular locale. E.g. zh_CN would return zh, while zh_TW would return zt. | |
getAvailableLanguages () | |
Returns an array of all available languages in the application. This is derived from all languages listed in the [languages] section of the conf.ini file. | |
Configuration & Initialization | |
Methods and Data Structures for Storing and Accessing Configuration. | |
$_conf | |
A configuration array to store configuration information. | |
db () | |
Returns MySQL connection resource. | |
Dataface_Application ($conf=null) | |
Constructor. Do not use this. getInstance() instead. | |
& | conf () |
Returns the config array as loaded from the conf.ini file, except that it opens up the opportunity for the delegate class to load values into the config using its own conf() method. | |
getMySQLMajorVersion () | |
Get the mysql major version number of MySQL. returns int. | |
getSiteTitle () | |
Gets the site title. | |
static & | getInstance ($conf=null) |
Returns reference to the singleton instance of this class. | |
Session Handling | |
Methods and data structures for dealing with Session Handling and authentication. | |
saveMessage ($str) | |
Sets a message to be displayed as an info/alert the next time a page is rendered. This is handy if your action is performing some funcitons and then redirecting to a new page on complete - and you want the message to be displayed on the other page. | |
enableSessions () | |
Sets the cookie that causes sessions to be enabled by default. In order to maximize performance Xataface will try not to start a session until it absolutely has to . This allows public sites to not rack up huge amounts of Session files unnecessarily. | |
disableSessions () | |
Unsets the cookie that causes sessions to be enabled by default. Despite the name, this doesn't actually disable sessions. Sessions will still be enabled when they are needed, eg for login. This will just enable them always by default. | |
sessionEnabled () | |
Checks if sessions are enabled by default. | |
startSession ($conf=null) | |
Starts a session if one does not already exist. If you are writing code that needs to use session data it is a good idea to explicitly call this before doing anything with the $_SESSION array. It is safe to call this multiple times. | |
& | getAuthenticationTool () |
Obtains reference to the authentication tool. | |
Template & UI Interaction | |
Methods for customizing the output. This includes error messages, and inclusion of content in the head of the document. | |
addHeadContent ($content) | |
Adds some content meant to be inserted in the head of the application. | |
getNavItem ($key, $label=null) | |
Returns the nav item info for a key. This is a wrapper around the nav items defined in the [_tables] section of the conf.ini file. | |
isNavItemSelected ($key) | |
Checks whether the specified nav item is currently selected. This is used by the default implementation of getNavItem() and it an be used also in custom implementations. It can also be overridden by the application delegate class method of the same name. | |
addError ($err) | |
Adds an error to be displayed in the UI in the messages block. | |
numErrors () | |
Returns the number of errors that are to be displayed to the user in the messages block. | |
getErrors () | |
Returns an array of the errors that are set to be displayed to the user in the messages block. | |
addMessage ($msg) | |
Adds a message to be displayed in the messages block. | |
getMessages () | |
Gets the messages that are to be displayed in the messages block. This will look in multiple sources for possible messages to display. It will include the following: | |
clearMessages () | |
Clears all of the message to be displayed. | |
numMessages () | |
Returns the number of messages to be displayed to the user. | |
static & | getResponse () |
Returns the response array used for compiling response. The response may include messages that need to be displayed to the screen as an alert. Currently the response array only includes a single key: --msg. | |
Request Handling | |
Methods for handling the main requests. These methods are responsible for doing the heaving lifting of displaying a page. | |
handleRequest ($disableCache=false) | |
Handle a request. This method is the starting point for all Dataface application requests. It will delegate the request to the appropriate handler. The order of delegation is as follows: | |
display ($main_content_only=false, $disableCache=false) | |
Displays the Dataface application. | |
Utility Functions | |
Useful functions that are informed by the current context to provide useful functionality to the application as a whole. | |
$_parseStringContext = array() | |
parseString ($expression, $context=null) | |
Evaluates a string expression replacing PHP variables with appropriate values in the current record. | |
testCondition ($condition, $context=null) | |
Tests an expression for a boolean result. This is primarly used by the condition directive of actions to be able to evaluate boolean expressions to determine if an action should be visible or not. | |
url ($query, $useContext=true, $forceContext=false) | |
Builds a link to somewhere in the application. This will maintain the existing query information. | |
registerUrlFilter ($filter) | |
Registers a filter that acts on URLs that are build with link builder. This allows modules to affect URLs as they are built to add, remove, or change parameters. | |
filterUrl ($url) | |
Filters a URL to add the current table and apply any filters that have been registered using registerUrlFilter() | |
redirect ($url) | |
Redirects the browser to a particular URL. Using this method rather than using a Location HTTP header directly is preferred as it allows modules to hook in to provide their own redirect handler to override the redirect. |
The main Application object that handles requests and response.
This is the one object that is presumed to always exist in a Dataface request.
<?php require_once 'xataface/public-api.php'; df_init(__FILE__, '/dataface')->display();
Definition at line 87 of file Application.php.
addError | ( | $ | err | ) |
Adds an error to be displayed in the UI in the messages block.
PEAR_Error | $err | The error that is being added. |
Definition at line 1606 of file Application.php.
addHeadContent | ( | $ | content | ) |
Adds some content meant to be inserted in the head of the application.
string | $content |
$app->addHeadContent('<link rel="stylesheet" type="text/css" href="styles.css"/>');
Definition at line 1524 of file Application.php.
addMessage | ( | $ | msg | ) |
Adds a message to be displayed in the messages block.
string | $msg | The messag to be displayed. |
Definition at line 1639 of file Application.php.
checkPermission | ( | $ | perm | ) |
Checks if a permission is granted in the current context.
This is essentially a wrapper around the getPermissions() method that goes on to check for the existence of a permission.
string | $perm | The name of a permission to check. |
Definition at line 2741 of file Application.php.
clearMessages | ( | ) |
Clears all of the message to be displayed.
Definition at line 1672 of file Application.php.
& conf | ( | ) |
Returns the config array as loaded from the conf.ini file, except that it opens up the opportunity for the delegate class to load values into the config using its own conf() method.
This is useful if an application wants to store config information in the database and still make it available to the application.
Definition at line 995 of file Application.php.
Dataface_Application | ( | $ | conf = null | ) |
Constructor. Do not use this. getInstance() instead.
The garbage collector threshold is the number of seconds that "garbage" can exist for before it is deleted. Examples of "garbage" include import tables (ie: temporary tables created as an intermediate point to importing data).
Definition at line 469 of file Application.php.
db | ( | ) |
Returns MySQL connection resource.
Definition at line 459 of file Application.php.
disableSessions | ( | ) |
Unsets the cookie that causes sessions to be enabled by default. Despite the name, this doesn't actually disable sessions. Sessions will still be enabled when they are needed, eg for login. This will just enable them always by default.
Definition at line 1295 of file Application.php.
display | ( | $ | main_content_only = false , |
$ | disableCache = false |
||
) |
Displays the Dataface application.
boolean | $main_content_only | Whether to only show the main content or to show the full page with header and footer. This parameter is not respected by many of the current templates and may be removed in later releases. |
boolean | $disableCache | Whether to disable the output cache. It is enabled by default. |
Definition at line 2134 of file Application.php.
enableSessions | ( | ) |
Sets the cookie that causes sessions to be enabled by default. In order to maximize performance Xataface will try not to start a session until it absolutely has to . This allows public sites to not rack up huge amounts of Session files unnecessarily.
Definition at line 1282 of file Application.php.
filterUrl | ( | $ | url | ) |
Filters a URL to add the current table and apply any filters that have been registered using registerUrlFilter()
string | $url | The URL to be filtered. |
Definition at line 2595 of file Application.php.
fireEvent | ( | $ | name, |
$ | params = null |
||
) |
Fires an event to all event listeners.
string | $name | The name of the event. e.g. afterInsert |
array | $params | Array of parameters to pass to the event listener. |
Definition at line 1729 of file Application.php.
& getAction | ( | ) |
Gets the settings array for the current action as specified by the -action parameter of the current query.
Definition at line 1237 of file Application.php.
& getAuthenticationTool | ( | ) |
Obtains reference to the authentication tool.
Definition at line 1471 of file Application.php.
getAvailableLanguages | ( | ) |
Returns an array of all available languages in the application. This is derived from all languages listed in the [languages] section of the conf.ini file.
[languages] en=English fr=French
$app->getAvailableLanguages();
array( en => English fr => French )
Definition at line 431 of file Application.php.
getCustomPageLabel | ( | $ | name | ) |
Obtains the label for a custom page. The label is the same as the name except with capitalization of words and replacement of underscores with spaces.
string | $name | The custom page name. |
Definition at line 2862 of file Application.php.
getCustomPagePath | ( | $ | name | ) |
Obtains the full path (read for inclusion) of the custom page with name $name.
string | $name | The name of a custom page. |
Definition at line 2849 of file Application.php.
& getCustomPages | ( | ) |
PHP files located in the 'pages' directory of the site are considered to be custom pages. Passing the GET parameter -action=custom_<pagename> will cause the Application controller to display the page <pagename>.php from the pages directory. This method just returns an array of full paths to the custom pages that are available in the 'pages' directory.
Definition at line 2822 of file Application.php.
& getDelegate | ( | ) |
Returns a reference to the delegate object for this application. The delegate object can be used to define custom functionality for the application.
Definition at line 2666 of file Application.php.
getErrors | ( | ) |
Returns an array of the errors that are set to be displayed to the user in the messages block.
Definition at line 1627 of file Application.php.
getEventListeners | ( | $ | name = null | ) |
Gets a list of the callbacks that are registered for a given event.
$name | The name of the event for which the callbacks are registered. |
Definition at line 1774 of file Application.php.
static& getInstance | ( | $ | conf = null | ) | [static] |
Returns reference to the singleton instance of this class.
array | $conf | Optional configuration associative array that matches the stucture of the conf.ini file. This parameter will only be considered the first time this method is called in the request. |
$app = Dataface_Application::getInstance(); $app->display();
Definition at line 969 of file Application.php.
getLanguage | ( | $ | langCode | ) |
Returns the language associated with a given language code.
string | $langCode | The 2-digit xataface language code. May be non-standard. |
Given a languages section in your conf.ini file that resembles:
zh zh
Definition at line 368 of file Application.php.
getLanguageCode | ( | $ | locale | ) |
Returns the Xataface language code for a particular locale. E.g. zh_CN would return zh, while zh_TW would return zt.
string | $locale | A local in the form <lang>_<COUNTRY>. E.g. en_US or zh_CN |
echo $app->getLanguageCode('zh_TW');
zh
Definition at line 394 of file Application.php.
getMessages | ( | ) |
Gets the messages that are to be displayed in the messages block. This will look in multiple sources for possible messages to display. It will include the following:
Definition at line 1654 of file Application.php.
getMySQLMajorVersion | ( | ) |
Get the mysql major version number of MySQL. returns int.
Definition at line 1027 of file Application.php.
getNavItem | ( | $ | key, |
$ | label = null |
||
) |
Returns the nav item info for a key. This is a wrapper around the nav items defined in the [_tables] section of the conf.ini file.
This can be overridden using the Application Delegate class method of the same name.
string | $key | The key of the nav item. This would be the table name if using the traditional simple table nav items. |
string | $label | The label for the nav item. This would be the table label if using the traditional simple table nav items. |
href => The URL where the nav item is to link label => The label for the nav item. selected => boolean value indicating whether the item is currently selected.
Definition at line 1549 of file Application.php.
getPermissions | ( | $ | params = array() | ) |
Returns the permissions that are currently available to the user in the current context. If we are in browse mode then permissions are checked against the current record. Otherwise, permissions are checked against the table.
This will first try to get the permissions on the current record (as retrieved via getRecord()), and if no record is currently selected, it will get the permissions on the current table.
array | $params | Parameters that can be passed to getPermissions to specify a particular field or relationship. |
Definition at line 2714 of file Application.php.
& getQuery | ( | ) |
Returns a reference to the current query object. This is very similar to the $_GET and $_REQUEST globals except this array has been filled in with missing values.
$query =& $app->getQuery(); if ( $query['-table'] == 'dashboard' ){ // Always set the action for the dashboard to 'dashboard_action' $query['-action'] = 'dashboard_action'; }
Definition at line 1094 of file Application.php.
& getQueryParam | ( | $ | key | ) |
Returns a query parameter.
string | $key | The query parameter to obtain. This should omit the leading '-' in the parameter name. E.g. Instead of '-action' this will be 'action'. |
Output:
my_table my_table
Definition at line 1121 of file Application.php.
& getRecord | ( | ) |
Gets the current record based on the current query.
array(
user_id => 10
)
@code
We have @code
$rec = $app->getRecord(); // Record with user_id 10.
Given the query:
array(
user_id => 10,
-recordid => 'users?user_id=11'
)
We have
$rec = $app->getRecord() // Record with user_id 11
Definition at line 1187 of file Application.php.
static& getResponse | ( | ) | [static] |
Returns the response array used for compiling response. The response may include messages that need to be displayed to the screen as an alert. Currently the response array only includes a single key: --msg.
--msg => <string>
Definition at line 1698 of file Application.php.
& getResultSet | ( | ) |
Loads the current result set.
Definition at line 1134 of file Application.php.
getSiteTitle | ( | ) |
Gets the site title.
If $app->_conf['title'] is set then this will just return that. If not it will determine an appropriate title based on the current record and the current table.
Definition at line 1045 of file Application.php.
handleRequest | ( | $ | disableCache = false | ) |
Handle a request. This method is the starting point for all Dataface application requests. It will delegate the request to the appropriate handler. The order of delegation is as follows:
boolean | $disableCache | Whether to disable the cache or not for this request. |
Definition at line 1824 of file Application.php.
isNavItemSelected | ( | $ | key | ) |
Checks whether the specified nav item is currently selected. This is used by the default implementation of getNavItem() and it an be used also in custom implementations. It can also be overridden by the application delegate class method of the same name.
string | $key | The nav item key. Traditionally the table name if using simple table navigation items. |
Definition at line 1583 of file Application.php.
numErrors | ( | ) |
Returns the number of errors that are to be displayed to the user in the messages block.
Definition at line 1618 of file Application.php.
numMessages | ( | ) |
Returns the number of messages to be displayed to the user.
Definition at line 1680 of file Application.php.
parseString | ( | $ | expression, |
$ | context = null |
||
) |
Evaluates a string expression replacing PHP variables with appropriate values in the current record.
string | $expression | A string containing PHP variables that need to be evaluated. |
Dataface_Record | $context | A Dataface_Record, Dataface_RelatedRecord object, or array whose values are treated as local variables when evaluating the expression. |
Variable | Type | Description |
---|---|---|
$site_url | String | The Site URL (i.e. DATAFACE_SITE_URL). This includes the URL to the folder containing the application. It doesn't include the index.php file. |
$site_href | String | The Site HREF (i.e. DATAFACE_SITE_HREF). This is the URL to the index.php file. |
$dataface_url | String | The URL to the Xataface directory. |
$table | String | The name of the current table. |
$tableObj | Dataface_Table | Reference to the Dataface_Table object encapsulating the current table. |
$query | array | The current query array. See getQuery() |
$resultSet | Dataface_QueryTool | The current query result set. See getResultSet() |
$record | Dataface_Record | The current record. This may be obtained from the 'record' key of the $context parameter. If omitted, then this will be the result of getRecord() |
$relationship | Dataface_Relationship | The current relationship. This may be passed as the 'relationship' key of the $context parameter. If omitted then it is loaded from the current table and the $query['-relationship'] parameter. |
Definition at line 2350 of file Application.php.
recordLoaded | ( | ) |
Checks is the current record has been loaded yet.
Definition at line 1226 of file Application.php.
redirect | ( | $ | url | ) |
Redirects the browser to a particular URL. Using this method rather than using a Location HTTP header directly is preferred as it allows modules to hook in to provide their own redirect handler to override the redirect.
string | $url | The URL to redirect to. |
Definition at line 2633 of file Application.php.
registerEventListener | ( | $ | name, |
$ | callback | ||
) |
Registers an event listener to respond to events of a certain type.
string | $name | The name of the event to register for. e.g. afterInsert |
mixed | $callback | A standard PHP callback. Either a function name or an array of the form array(&$object,'method-name'). |
Definition at line 1748 of file Application.php.
registerUrlFilter | ( | $ | filter | ) |
Registers a filter that acts on URLs that are build with link builder. This allows modules to affect URLs as they are built to add, remove, or change parameters.
callback | $filter | A callback function that follow the PHP callback conventions and call be called with call_user_func. This should accept a string as a input and provide the modified string as output. |
A filter to add -foo=1 to the end of all URLs:
function addFoo($string){ return $string.'&-foo=1'; } $app = Dataface_Application::getInstance(); $app->registerUrlFilter('addFoo'); // Now any URL produced will include &-foo=1 at the end of it $url = $app->url(''); // Outputs index.php?-table=test&-action=list&-foo=1
Definition at line 2581 of file Application.php.
saveMessage | ( | $ | str | ) |
Sets a message to be displayed as an info/alert the next time a page is rendered. This is handy if your action is performing some funcitons and then redirecting to a new page on complete - and you want the message to be displayed on the other page.
string | $str | The message that should be displayed. |
$app->saveMessage("The record was saved successfully.");
Definition at line 1269 of file Application.php.
sessionEnabled | ( | ) |
Checks if sessions are enabled by default.
Definition at line 1307 of file Application.php.
startSession | ( | $ | conf = null | ) |
Starts a session if one does not already exist. If you are writing code that needs to use session data it is a good idea to explicitly call this before doing anything with the $_SESSION array. It is safe to call this multiple times.
array | $conf | Optional configuration data that should follow the format of $app->_conf['_auth'] |
Definition at line 1322 of file Application.php.
testCondition | ( | $ | condition, |
$ | context = null |
||
) |
Tests an expression for a boolean result. This is primarly used by the condition directive of actions to be able to evaluate boolean expressions to determine if an action should be visible or not.
string | $condition | A string that is executed in the sandbox context. |
array | $context | Extra context information to include. This does not allow arbitrary variables to be added to the context, only specific ones. |
Variable | Type | Description |
---|---|---|
$site_url | String | The Site URL (i.e. DATAFACE_SITE_URL). This includes the URL to the folder containing the application. It doesn't include the index.php file. |
$site_href | String | The Site HREF (i.e. DATAFACE_SITE_HREF). This is the URL to the index.php file. |
$dataface_url | String | The URL to the Xataface directory. |
$table | String | The name of the current table. |
$tableObj | Dataface_Table | Reference to the Dataface_Table object encapsulating the current table. |
$query | array | The current query array. See getQuery() |
$resultSet | Dataface_QueryTool | The current query result set. See getResultSet() |
$record | Dataface_Record | The current record. This may be obtained from the 'record' key of the $context parameter. If omitted, then this will be the result of getRecord() |
$relationship | Dataface_Relationship | The current relationship. This may be passed as the 'relationship' key of the $context parameter. If omitted then it is loaded from the current table and the $query['-relationship'] parameter. |
Definition at line 2479 of file Application.php.
unregisterEventListener | ( | $ | name, |
$ | callback | ||
) |
Unregisters an event listener.
Definition at line 1760 of file Application.php.
url | ( | $ | query, |
$ | useContext = true , |
||
$ | forceContext = false |
||
) |
Builds a link to somewhere in the application. This will maintain the existing query information.
mixed | $query | Either a query string or a query array. |
boolean | $useContext | Whether to use the existing context variables or not. |
boolean | $forceContext | Whether to force context. |
echo $app->url(array('-action'=>'browse'));
/path/to/app/index.php?-table=foo&action=browse&username=ted
(Actually this isn't entirely correct... the entire context will also be included and Xataface calculates some default context parameters at the beginning of every request so the actually result will include parameters like -skip, -limit, -cursor, etc.. as well).
Definition at line 2537 of file Application.php.
$_conf |
A configuration array to store configuration information.
Definition at line 464 of file Application.php.
$_parseStringContext = array() |
Definition at line 2282 of file Application.php.
$prefs |
array( 'show_result_stats'=>1, 'show_jump_menu'=>1, 'show_result_controller'=>1, 'show_table_tabs'=>1, 'show_actions_menu'=>1, 'show_logo'=>1, 'show_tables_menu'=>1, 'show_search'=>1, 'show_record_actions'=>1, 'show_recent_records_menu'=>1, 'show_bread_crumbs' => 1, 'show_record_tabs' => 1, 'show_record_tree' => 1, 'list_view_scroll_horizontal'=>1, 'list_view_scroll_vertical'=>1 )
User preferences matrix.
Definition at line 219 of file Application.php.
$rawQuery |
Definition at line 182 of file Application.php.
$redirectHandler = null |
An object that implements a method named 'redirect' that is supposed to handle requests to redirect to a new page. This gives an opportunity to suppress redirects or handle them differently inline. This is helpful if you're loading Xataface from a cron script or another application and need to prevent redirects.
$app = Dataface_Application::getInstance(); class MyHandler { function redirect($url){ echo "A request to redirect to $url."; } } $app->redirectHandler = new MyHandler(); $app->display();
Note that if your handler does not either throw an exception or exit execution, then Xataface will throw a Dataface_Application_RedirectException which can be caught higher up the call stack.
Definition at line 117 of file Application.php.
const EX_FAILED_TO_CREATE_SESSION_DIR = 5500 |
Definition at line 89 of file Application.php.