Manage configuration from database
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist sersid/yii2-user-profile "dev-master"
or add
"sersid/yii2-user-profile": "dev-master"
to the require section of your composer.json
file.
Applying migrations
yii migrate --migrationPath=@vendor/sersid/yii2-user-profile/migrations
$config = [
...
'components' => [
...
'profile' => [
'class' => 'sersid\profile\components\Profile',
],
]
];
Once the extension is installed, simply use it in your code by :
Yii::$app->profile->set('foo', 'bar');
Yii::$app->profile->set(['foo' => 'bar']);
Yii::$app->profile->get('foo'); // bar
Yii::$app->profile->model(); // sersid\profile\models\Model
Create migration
yii migrate/create profile_fields
use yii\db\Schema;
use yii\db\Migration;
class m150317_155953_profile_fields extends Migration
{
public function up()
{
$this->addColumn('{{%profile}}', 'lang', Schema::TYPE_STRING);
// ... your fields
}
public function down()
{
$this->dropColumn('{{%profile}}', 'lang');
// ... your fields
}
}
Update model
namespace app\models;
use sersid\profile\models\Model;
class Profile extends Model
{
const LANG_EN = 'en';
const LANG_RU = 'ru';
/**
* @inheritdoc
*/
public function rules()
{
return [
['lang', 'default', 'value' => self::LANG_EN],
['lang', 'in', 'range' => [self::LANG_EN, self::LANG_RU]],
// ... your rules
];
}
}
$config = [
...
'components' => [
...
'profile' => [
'class' => 'sersid\profile\components\Profile',
'model' => 'app\models\Profile',
],
]
];
Applying migrations
yii migrate/down --migrationPath=@vendor/sersid/yii2-user-profile/migrations
No stable releases.
Comments