mhunesi/yii2-csc

Yii2 国家、州、城市迁移和模型。

安装: 13

依赖项: 0

建议者: 0

安全性: 0

星星: 0

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

v1.0.2 2022-12-06 08:27 UTC

This package is auto-updated.

Last update: 2024-09-06 12:24:48 UTC


README

Yii2 国家、州、城市迁移和模型。

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

php composer.phar require --prefer-dist mhunesi/yii2-csc "*"

或在您的 composer.json 文件的 require 部分添加

"mhunesi/yii2-csc": "*"

to

用法

扩展安装完成后,只需在您的代码中通过

'controllerMap' => [
    'migrate' => [
            //..
        'migrationNamespaces' => [
            //..
        ],
        'migrationPath' => [
            //..
            '@mhunesi/csc/migrations'
        ]
    ]
],

来使用它,并运行迁移

php yii migrate

模型

  • 国家
  • 城市
use mhunesi\csc\models\Country;
use mhunesi\csc\models\State;
use mhunesi\csc\models\City;

//Example 1
/** @var Country[] $country */
$country = Country::find()->all();

/** @var State[] $states */
$states = $country->states;

foreach ($states as $state) {
    /** @var City[] $cities */
    $cities = $state->cities
}

//Example 2

Country::find()->where(['iso2' => 'TR'])->one();

State::find()->where(['country_code' => 'TR'])->all();