定制 sersid/yii2-user-profile 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sersid/yii2-user-profile

Composer 安装命令:

composer require sersid/yii2-user-profile

包简介

Yii2 user profile

README 文档

README

Manage configuration from database

Installation

One

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.

Two

Applying migrations

yii migrate --migrationPath=@vendor/sersid/yii2-user-profile/migrations

Three

$config = [
    ...
    'components' => [
        ...
        'profile' => [
            'class' => 'sersid\profile\components\Profile',
        ],
    ]
];

Usage

Once the extension is installed, simply use it in your code by :

Set

Yii::$app->profile->set('foo', 'bar');
Yii::$app->profile->set(['foo' => 'bar']);

Get

Yii::$app->profile->get('foo'); // bar

Model

Yii::$app->profile->model(); // sersid\profile\models\Model

Create fields

One

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
    }
}

Two

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
        ];
    }
}

Three

$config = [
    ...
    'components' => [
        ...
        'profile' => [
            'class' => 'sersid\profile\components\Profile',
            'model' => 'app\models\Profile',
        ],
    ]
];

Uninstall

Applying migrations

yii migrate/down --migrationPath=@vendor/sersid/yii2-user-profile/migrations

统计信息

  • 总下载量: 84
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-03-17