Gadget
The static Gadget class provides all methods you will usually need to perform the most tasks needed to be done while working with the Gadget WDK.
It provides methods for retreiving/manipulating configuration, cookies, user preferences and "the current user". There are two methods that need to be called at script start, respectively at script end, namely Gadget::start() and Gadget::finish(), which will initialize Gadget's infrastructure and render all instantiated widgets. See the documentation of the methods itself for more information.
Example: A basic Gadget powered page:
- require_once 'Gadget.php';
- Gadget::start();
- // display login box if
- // visitor is not logged in
- if (!Gadget::currentUser()) {
- Gadget::newWidget('LoginBox');
- }
- // display intro if user is not
- // logged in or it's his preference
- if (!Gadget::currentUser() or Gadget::getPref('display_intro')) {
- Gadget::newWidget(array('template' => 'intro.html'));
- }
- // display home page
- Gadget::newWidget(array('template' => 'index.html'));
- // build a tiny menu
- // NOTE that the point when you have to build the menu
- // depends on your chosen layout;
- $menu = &Gadget::newWidget('Menu');
- $sect = &$menu->addSection('Navigation');
- $sect->addLink('Home', '/');
- $sect->addLink('About', '/about.php');
- $sect = &$menu->addSection('Downloads', '/downloads/');
- $sect->addLink('GNU/Linux', '/downloads/linux.php');
- $sect->addLink('MS Win32', '/downloads/wikndows.php');
- Gadget::finish();
Located in /Gadget.php (line 146)
Breadcrumbs
This returns the Breadcrumbs widget instance.
Call Provider Get
This executes the get() method of a certain Gadget_Provider and returns the results of the method call. Note that the arguments will be passed to call_user_func_array().
Call Provider Set
This executes the set() method of a certain Gadget_Provider and returns the results of the method call. Note that the arguments will be passed to call_user_func_array().
Current User
Retreive an attribute of the current user (defaults to users id). If $get === true the users DataObject will be returned. Returns 0 if the user is anonym.
Setup a DB_DataObject
This calls DB_DataObject::factory() to create a new entity unless called without argument, then it just does the necessary work to properly setup DB_DataObject by retreiving its options through Gadget::getConf('Db_DataObject').
Remove Params from QueryString
This operates directly on $_SERVER['QUERY_STRING'] and removes parameters specified by $params. This is very useful if you ise Apache's mod_rewrite or similar hooks to prettify URLs. It returns the modifed query string.
Finish
Gadget::finish() must be called at sript/page end. It renders all widgets remaining in the widget queue one after another (unless $widget->show is FALSE). By default the PageFooter widget will be instantiated right before the widget queue gets rendered.
Get Config
Retreive a configuration setting. In the default setup where Gadget_Provider_Configuration is used, the settings are stored within a plain INI file. Define the GADGET_CONFIG constant to point to your INI configuration file.
Get Current User
Retreive the current users DataObject.
Get Preferences
Retreive a preferences item or all preferences if $pref is NULL. If the user has no preferences yet or the user is anonym the default preferences (defined by configuration) are being returned.
Get Params from QueryString
Handle PEAR Error
PageHeader
This returns the PageHeader instance.
Locale
This returns the I18Nv2_Locale instance configured with the locale/language retreived by Gadget::getPref('language').
Location
Get the current location (being the request URI without query string).
Log
Login
Performs the login task. It will regenerate the session id, set the "current user" and redirect to $_GET['uri'] if this parameter is present.
Logout
Performs the logout task. It'll regenerate the session id, delete all session variables and finally destroy the session. It will further disable autologin (delete the autologin cookie) and redirect to the home page.
Modify QueryString
New Widget
This will instantiate and return a new widget $widget, configured by $options. You need to have a directory named "Widgets" in your include path where your custom widgets reside. If called only with one parameter being an array, a Gadget_Widget will be returned and the first parameter will be passed through to Gadget_Widget::setOptions().
Set Error Handling
Configure what action to take if a PEAR error occurs. Returns the previous error mode.
Add Error Mode
Add error mode to the actual error handling. Returns the previous error mode.
Sub Error Mode
Substract error mode from the actual error handling. Returns the previous error mode.
Create an persistent Object
This is a general purpose singleton, which can instantiate classes named after the PEAR coding standard or from file $file. Note that objects instantiated through this method are kept alive and may be used after their first instantiation. Also note that these classes may only require one construction parameter.
Create an persistent Widget
This created persitent widgets like the PageHeader. This is necessary to be able to add style sheets, javascripts, links etc. to the head section within any widget by retreiving the PageHeader widget through &Gadget::header();.
Provider
Provider singleton. Returns *the* instance of a certain Gadget_Provider object. It's basically a shorthand for:
- require_once 'Gadget/Provider.php';
- Gadget_Provider::singleton($provider);
Execute Service
This executes the run() method of a certain Gadget_Service and returns the results of the method call.
Service
Service singleton. Returns *the* instance of a certain Gadget_Service object. It's basically a shorthand for:
Note that it does *NOT* call the run() method of the service.
- require_once 'Gadget/Service.php';
- Gadget_Service::singleton($service);
Set Config
Set a configuration setting. In the default setup where Gadget_Provider_Configuration is used, this only overrides configuration for the time the current script is executed.
Set Current User
Set the current user through its id.
Set Preferences
Modify the users preferences. If the user is anonym the modified preferences will be stored in the session.
Start
This starts Gadget and is usually called at the very beginning of your page/script. It does the following in right this order:
Start & Negotiate I18N
Timer
Returns the time difference from Gadget::start() to the point of calling.
Documentation generated on Sun, 03 Jul 2005 12:45:46 +0200 by phpDocumentor 1.3.0RC3