Loading...
 
Skip to main content

History: Ex-ante functions

Source of version: 13 (current)

Copy to clipboard
This page documents useful functions available to be called __before__ executing data modifications (insert/update/delete) using a service controller.

!!Authenticity (ticket) checking
Check if the user has authenticity to prevent [http://en.wikipedia.org/wiki/Cross-site_request_forgery|CSRF].

{CODE()}$access->check_authenticity() 
//function to prevent CSRF by including a ticket in the popup form{CODE}

{CODE(caption="Include ticket in smarty tpl" wrap="1" colors="smarty")}<input type="hidden" name="ticket" value="{$ticket}">{CODE}

!!Preference checking
Check if a preference (feature) is enabled.  
{CODE()}//check preference 
Services_Exception_Disabled::check('feature_wiki_structure');{CODE}

If you want to check several preferences, call each separately
{CODE()}//check preferences
Services_Exception_Disabled::check('feature_wiki');
Services_Exception_Disabled::check('feature_wiki_structure');
Services_Exception_Disabled::check('feature_wiki_export');{CODE}

!!Permission checking
Check for necessary permissions (tiki_p_XXXX)
{CODE()}//check permission
$permission = Perms::get();
if (! $permission->tiki_p_edit_menu_options) {
throw new Services_Exception_Denied(tr('Permission denied'));
}{CODE}

!!Checking mandatory input
Check if a mandatory input data is available and fire error it is if not provided

!!Call a function from a library
You will probably need to use some functions from libraries.

!!!Initialize the library
{CODE()}$structLib = TikiLib::lib('struct');{CODE}

{REMARKSBOX(type="tip" title="Tiki libs" close="n")}
{CODE()}db/config/tiki.xml{CODE}
{REMARKSBOX}
!!!Call the function
{CODE()}$structLib->move_to_structure($page_ref_id, $structure_id);{CODE}
Show PHP error messages