- ^ References
- ^ Class utilities
- jApp: directories of the application
- jFilter: verifying and filtering datas
- jDateTime: dates and times
- jHttp: http requests
- jMailer: sending mails
- jWiki: generating contents from wiki contents
- jSession: managing sessions
- jMessage: short messages between actions
- jFile: file processing
- jPref: using application preferences
Section: jPref: using application preferences
|« jFile: file processing||^ Class utilities|
jPref is a simple class allowing to save and retrieve some preferences by your application. By "preferences", we mean some options that can be changed by the user or that can be change during the life of the application. Options of mainconfig.ini.php and other are technical preferences that don't supposed to change.
jPref is a class provided by the "jpref" module. Activate it
in your configuration:
[modules] jpref.access = 1
And run the application installer.
jPref is a class that use
jKVDb. So to use jPref, you just
have to define a profile for
jkvdb, having "jpref" as name.
In your profiles.ini.php:
To know more about configuration of jKvdb, see its documentation.
jPref::get($key): to retrieve a preference.
jPref::set($key, $value, $ttl): so modify/save a preference.
jPref::set('nb.items.per.page', 20); $val = jPref::get('nb.items.per.page'); // $val contains 20
Admin interface for jPref ¶
A module jpref_admin is provided, to manage preferences from the administration interface. Pages are directly accessible from the "System" menu of master_admin.
However you should fill the file
add preferences that are editable, and how : their label, default value,
rights to read and modify...
Declaring a preference ¶
You need to declare the preference only if you want to manage it from jpref_admin (it is the case most of time, or consider to put the parameter into mainconfig.ini.php).
preferences.ini.php, you have a section for each
preferences, with the prefix "pref:" :
[pref:preference.name] ; "string" | "integer" | "boolean" | "decimal" (défaut string) type = ; locale key for the label locale = ; preference group (see below) group = ; jAcl2 subject corresponding to the right to read the preference value read_acl_subject = ; jAcl2 subject corresponding to the right to modify the preference value write_acl_subject = ; default value default_value =
Note: each parameters are optional.
write_acl_subject allow to restrict the access
to preferences. Some preferences may not be accessible only by administrator
of the web site for example. So you should defines some rights in jAcl2,
and indicate here the corresponding "subjects". If
write_acl_subject are not filled, the preference can be modified by
any user (except if the user has not the right "jprefs.prefs.list").
Declaring a preferences group ¶
Your preferences can be grouped, so it can be easier to manage them. You can have a group per module for example.
preferences.ini.php, declare a section with a prefix "group:".
A section contains the label of the group, and an order value.
[group:nom.syteme.de.la.pref] ; locale key of the label locale = ; display order order =
Note: each parameters are optional.
[group:contact] locale = "contact~admin.pref.group.contact" order = 1 [pref:telephone] type = string locale = "contact~admin.pref.telephone" group = "contact" read_acl_subject = write_acl_subject = "contact.edit.infos" default_value = [group:shop] locale = "contact~admin.pref.group.contact" order = 2 [pref:nb.items.per.page] type = integer locale = "shop_admin~admin.pref.nb.items.per.page" group = shop read_acl_subject = write_acl_subject = default_value = 15 [pref:shop.is.open] type = boolean locale = "shop_admin~admin.pref.shop.is.open" group = shop read_acl_subject = write_acl_subject = "shop.edit.shop.status" default_value = "false"