2017 © Pedro PelΓ‘ez
 

yii2-extension yii2-data-static

Yii2 Static Data

image

yiimaker/yii2-data-static

Yii2 Static Data

  • Tuesday, January 10, 2017
  • by YiiMaker
  • Repository
  • 2 Watchers
  • 2 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Yii2 Static Data

It is a model for the data that stores configuration. StaticData subject to the same rules as yii\base\Model, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist yiimaker/yii2-data-static "*"

or add, (*4)

``` json "yiimaker/yii2-data-static": "*", (*5)


to the require section of your `composer.json` file. Usage ----- 1. Configure component `yiimaker/yii2-configuration` in config file or in `StaticData` class. [More information](https://github.com/yiimaker/yii2-configuration#configuration) 2. Inherit the class `ymaker\data\statics\StaticData`, then describe it as a normal model. Example ------- StaticData ---------- ```php class AboutUs extends ymaker\data\statics\StaticData { public $phone; public $email; public function rules() { return [ [['phone', 'email'], 'required'], ['phone', 'string', 'max' => 255], ['email', 'email'] ]; } }
$aboutUs = new AboutUs();

Save Data

$aboutUs->phone = '+111111111111';
$aboutUs->email = 'test@example.com';
$aboutUs->save();

Load Data

$aboutUs->loadAttributes();
echo $aboutUs->email; // 'test@example.com';

or, (*6)

$aboutUs = AboutUs::getInstance();

Reload Data

$aboutUs->loadAttributes();
$aboutUs->email = 'another@example.com';
$aboutUs->reload();

echo $aboutUs->email; // 'test@example.com';

StaticDataTranslation

class AboutUs extends ymaker\data\statics\StaticDataTranslation
{
    public $address;

    public function rules()
    {
        return [
            [['address'], 'required'],
            ['address', 'string', 'max' => 255],
        ];
    }
}
$aboutUs = new AboutUs(['language' => 'en-US']);
// $about

Save Data

$aboutUs->address = 'Kiev, Ukraine';
$aboutUs->save();
$aboutUs->setLanguage('ru-RU');
$aboutUs->address = 'КиСв, Π£ΠΊΡ€Π°ΠΈΠ½Π°';
$aboutUs->save();

Load Data

$aboutUs->loadAttributes();
echo $aboutUs->address; // 'КиСв, Π£ΠΊΡ€Π°ΠΈΠ½Π°'
$aboutUs->changeLanguage('en-US');
echo $aboutUs->address; // 'Kiev, Ukraine'

or, (*7)

$aboutUs = AboutUs::getInstance(['language' => 'en-US']);

Reload Data

$aboutUs->loadAttributes();
$aboutUs->address = 'Π›ΠΎΠ½Π΄ΠΎΠ½, ВСликобритания';
$aboutUs->reload();

echo $aboutUs->address; // 'КиСв, Π£ΠΊΡ€Π°ΠΈΠ½Π°'

change language

    /**
     * change language for model
     * @param $language string language code
     * @param bool $reload If true, then all attributes will be overwritten
     */
    public function changeLanguage($language, $reload = true);
echo $aboutUs->address; // 'КиСв, Π£ΠΊΡ€Π°ΠΈΠ½Π°'
$aboutUs->changeLanguage('en-US');
echo $aboutUs->address; // 'Kiev, Ukraine'

$aboutUs->changeLanguage('ru-RU', false);
echo $aboutUs->address; // 'Kiev, Ukraine'

$aboutUs->reload();
echo $aboutUs->address; // 'КиСв, Π£ΠΊΡ€Π°ΠΈΠ½Π°'

The Versions

10/01 2017

1.2.2

1.2.2.0

Yii2 Static Data

  Sources   Download

BSD-3-Clause

The Requires

 

by Ruslan Saiko

extension yii2 static data

10/01 2017

dev-master

9999999-dev

Yii2 Static Data

  Sources   Download

BSD-3-Clause

The Requires

 

by Ruslan Saiko

extension yii2 static data

09/01 2017

1.2.1

1.2.1.0

Yii2 Static Data

  Sources   Download

BSD-3-Clause

The Requires

 

by Ruslan Saiko

extension yii2 static data

09/01 2017

1.1.3

1.1.3.0

Yii2 Static Data

  Sources   Download

BSD-3-Clause

The Requires

 

by Ruslan Saiko

extension yii2 static data

09/01 2017

1.0.3

1.0.3.0

Yii2 Static Data

  Sources   Download

BSD-3-Clause

The Requires

 

by Ruslan Saiko

extension yii2 static data

06/01 2017

1.1.2

1.1.2.0

Yii2 Static Data

  Sources   Download

Apache-2.0

The Requires

 

by Ruslan Saiko

extension yii2 static data

06/01 2017

1.2.0

1.2.0.0

Yii2 Static Data

  Sources   Download

Apache-2.0

The Requires

 

by Ruslan Saiko

extension yii2 static data

04/01 2017

1.1.1

1.1.1.0

Yii2 Static Data

  Sources   Download

Apache-2.0

The Requires

 

by Ruslan Saiko

extension yii2 static data

04/01 2017

1.0.2

1.0.2.0

Yii2 Static Data

  Sources   Download

Apache-2.0

The Requires

 

by Ruslan Saiko

extension yii2 static data

04/01 2017

1.1.0

1.1.0.0

Yii2 Static Data

  Sources   Download

Apache-2.0

The Requires

 

by Ruslan Saiko

extension yii2 static data

04/01 2017

1.0.1

1.0.1.0

Yii2 Static Data

  Sources   Download

Apache-2.0

The Requires

 

by Ruslan Saiko

extension yii2 static data

03/01 2017

1.0.0

1.0.0.0

Yii2 Static Data

  Sources   Download

Apache-2.0

The Requires

 

by Ruslan Saiko

extension yii2 static data