Download the PHP package futuretek/yii2-options without Composer
On this page you can find all versions of the php package futuretek/yii2-options. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-options
Yii2 Options
This extension provide application configuration support stored in database.
WARNING: Version 2.x introduces breaking changes. Upgrading from version 1.x is possible but requires additional actions.
Steps to migrate to version 2.x:
- Create options config for every used option item
- Include component in Yii2 config
- Rewrite commands to new syntax (or use compat class
futuretek\options\compat\Option
)
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Configuration
To start using this extension you have to load it in Yii config:
The component itself can be configured with the following properties:
Property | Default value | Description |
---|---|---|
db | db | The DB connection object or the application component ID of the DB connection. |
cache | cache | The cache object or the application component ID of the cache object. The option data will be cached using this cache object. |
optionTable | {{%option}} | The name of the option table. |
cachingDuration | 0 | The time in seconds that the options can remain valid in cache. Use 0 to indicate that the cached data will never expire. |
enableCaching | false | Whether to enable options caching |
configFile | Options config file. This file will be required. File must return config array. | |
config | Variable into which the config from configFile will be loaded. |
Notice: Option config is lazy-loaded on init (as opposite of including it in the application config). This is because the translation engine is not available at that time.
Option config/definition array contains list of the option groups.
Option group
Every option group consists of these attributes. Attributes marked with (*) are required.
- title (*) - Group title
- items (*) - Contains array of option items (see below)
- visible - If the group is visible
Option items
Option group attribute items
is array containing option items.
Option item consists of these attributes. Attributes marked with (*) are required.
- name (*) - Option name (unique)
- type () - Option type. See Option::TYPE_\ constants.
- title (*) - Option title
- hint - Option description
- visible - If the option is visible
- default - Specify option default value. Getting defined but unset option yields
this value. When not set,
null
will be returned. - context - If the option is context option. If this is true, option will not be rendered using provided actions.
- data - For option type=TYPE_OPTION this attribute contains data in form of:
- array of arrays containing keys id and name (see example below) or
- anonymous function returning the same array
ADVICE: If you need to create divider between options in the same option group,
simply put string as one of the items
array item.
Config example
Usage
This extension creates options
component for storing configuration.
Getting options
Setting options
Context options
Context comes handy in case you need to deal with storing different configuration for multiple entities (for example user configuration).
In this use case context can be uses. Simply specify entity identificator as context
and
entity record id as context_id
and you are done.
Getting and setting options is done via another arguments of methods get() and set().
Rendering settings page
If you want to render settings page, there is futuretek\options\IndesAction
provided.
You can simply add it to the controller actions()
method.
There is also futuretek\options\OptionsHelper
that provides method for rendering option
edit field based on option type.
See mentioned files for more details.
Development
Translations
Translations are managed trough standard Yii2 translations. To automatically register extension translations we recommend to use our another extension futuretek/yii2-composer.
To generate messages for translating run the following command in extension root directory.
Assets
Assets are managed by Compass
- While developing run
compass watch
in extension root directory - To compile assets for final distribution run
compass compile -e production --force
in extension root directory.
All versions of yii2-options with dependencies
yiisoft/yii2 Version ^2.0.0
yiisoft/yii2-bootstrap Version ^2.0.0
futuretek/yii2-migrations Version ^1.0.0