Config class

From Aikiframework wiki

Jump to: navigation, search

Contents

Abstract

The class must manage and encapsulated configuration variables and settings. Must allows multi-site, multi-view, and multi-language configuration.

Examples:

$aiki->config->get("title");
$aiki->config->set("news-in-homepage",5); // set permanently
$aiki->config->remember("debug","on"); // set only for actual page
$aiki->config->session("records-per-page",50); // set only for actual session.

Setting by site/view/language

Settings will be stored for site/view/language in a similar way of view and css parametrize. Example:

* : for all
mysite for mysite
*/dark/* for dark view
*/*/de for german
!mysite for all except my site
mysite/dark/ru 

Setting will be ordered descending by "important" (values: 0,1) and weight of selector calculated as:

* weight 0
site weigths: 100
view weights: 10
language: 1

Examples
* : 0 
mysite 100
*/dark/* 10
*/*/de 1
!mysite 100
mysite/dark/ru  111

So,"important" is a way to break weight rules similar to css !important


GETTING VALUES

Aiki look setting ordered by (descending) important, and weight, returning the first set that match.

set,selector, value
title, * , my first aiki
title, */*/eu , ni lehen aiki
title, */movil/*,  aiki.mobil
title, admin    , aiki-admin
author, *!important, somebody
author, mysite/*/*, nora

for sites:
title for mysite/dark/es => my first aiki
title for mysite/dark/eu => ni lehen a iki
title for myste/movil/eu => aiki.mobil
title for admin/movil/es => admin.
author for mysite/dark/de  => somebody.

Methods

$aiki->config->get $setting, default, site/view/language [current] )
Get a setting value for current site or provided site or default options if no exists.

$timeout = $aiki->config->get("timeout",5000);
if ( $aiki->config->get("cache",false) )..

$aiki->config->set( $setting, $value, $selector [*] )
Set permanently a variable for given selector (if provided) or for all *. You can also use five symbolic site: "CURRENT" (site/views/language" , CURRENT_SITE, CURRENT_VIEW, CURRENT_LANGUAGE, CURRENT_SITE_VIEW.

$aiki->config->remember( $setting, $value )
Set variable, but only for actual page. This can be useful for example in this case www.foo.bar?debug=on: you probably want debug all page but don't set debug on permanently.

$aiki->config->session( $setting, $value)
Similar as remember but with session scope. Useful for user some user preferences like records per page.


config()
A shortcut to $aiki->config->get;

Notes:

  • selector have no sense in remember (scope page) and session.
  • when get a value, current is actual site/view/language) but when set is all.

Table config

Settings must saved in TWO tables for all sites/views/ and language

One table, aiki_setting contains definition of setting:

  • id: internal auto-increment Key
  • name: string ( unique )
  • autoload: boolean. A mechanism to load in memory important setting (like wordpess for example).
  • can-remember: boolean,
  • edit-permission: which group can edit the setting.
  • format: how must be edited setting.
  • note/description: a brief text for documentation.
  • group: we need some way to group setting in 'pages'. You can add subgroup using "/". For example:

"cache", "appearance", "main/plugin", "appearance/colors"

The other table, aiki_configs, contains values for each selector. aiki_setting

  • id: internal auto-increment Key
  • name.
  • value.
  • weight.
  • important;

It's possible create a row in aiki_configs, that haven't a definition in aiki_setting. That means: - can't be edited. - can't be autoloaded. - but can be remember. - not permission is required, but set can only called via PHP.

construction

Class must:

  • autoload setting
  • establish remembers setting
  • restore session settings

Edit Method

$aiki->config->list_groups()

return HTML containing a list of groups which can edit current user. The purpose is create a widget with link to setting pages.

$aiki->config->edit( list of groups )

return HTML for edit a group of setting, or list of setting (array of names)

$aiki->config->edit_setting (list of settings)

return HTML for edit a unique setting.


$aiki->config->save()

Save a groups of variables sends via post (never, never use get)

Example:

$aiki->config->edit( cache,debug,html )
$aiki->config->edit( pagination)
&ltform name.....
lorem ipsum

$aiki->config->edit_setting( seo-keywords ) 

lorem ipsum
$aiki->config->edit_setting( seo-meta )


THE OLD $CONFIG array

The old global $config array will be used for two reason:

  • compatibility;
  • the config system only can work when site,viewn and language is calculated. All config setting that must be consulted before aiki->url and aiki->site run..must use the old method.

Database vs on-disk config.php

Database config will be default settings but if there is an on-disk config.php file, it will override the database configuration. This is a failsafe for system administrators.

Personal tools