PHP code example of yiiplus / yii2-kvstore
1. Go to this page and download the library: Download yiiplus/yii2-kvstore library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yiiplus / yii2-kvstore example snippets
'modules' => [
'kvstore' => [
'class' => 'yiiplus\kvstore\Module',
'sourceLanguage' => 'en'
],
...
],
...
'components' => [
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource'
],
],
],
'kvstore' => [
'class' => 'yiiplus\kvstore\Kvstore'
],
...
]
$kvstore = Yii::$app->kvstore;
$value = $kvstore->get('group.key');
$value = $kvstore->get('key', 'group');
$kvstore->set('group.key', 'value');
$kvstore->set('group.key', 'value');
$kvstore->set('key', 'value', 'group');
// Model
class Site extends Model {
public $siteName, $siteDescription;
public function rules()
{
return [
[['siteName', 'siteDescription'], 'string'],
];
}
public function fields()
{
return ['siteName', 'siteDescription'];
}
public function attributes()
{
return ['siteName', 'siteDescription'];
}
}
//Controller
function actions(){
return [
....
'site-kvstore' => [
'class' => 'yiiplus\kvstore\actions\KvstoreAction',
'modelClass' => 'app\models\Site',
//'group' => 'site',
//'scenario' => 'kvstore',
'viewName' => 'site-kvstore'
],
....
];
}
// Views
$form = ActiveForm::begin(['id' => 'site-kvstore-form']);
bash
php composer.phar