PHP code example of pozitronik / yii2-users-options

1. Go to this page and download the library: Download pozitronik/yii2-users-options 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/ */

    

pozitronik / yii2-users-options example snippets


'modules' => [
		'usersoptions' => [
			'class' => UsersOptionsModule::class,
			'params' => [
				'tableName' => 'auth_users_options',//используемое имя таблицы, по умолчанию 'users_options'
				'cacheEnabled' => true//использование кеша Yii, по умолчанию false
		],
		...
]


$options->serializer = [
	0 => function($value) {//функция для сериализации
		return json_encode($value);
	},
	1 => function(string $value) {//функция для десериализации
		return json_decode($value);
	},
];



declare(strict_types = 1);

namespace app\models;

use pozitronik\users_options\traits\UsersOptionsTrait;

/**
 * @property int $id
 * ...
 */
class AuthUsers extends ActiveRecord {
    use UsersOptionsTrait;

    /*...*/
}

$value = AuthUsers::findOne($id)->options->get($option);
AuthUsers::findOne($id)->options->set($option, $value);

php composer.phar