PHP code example of mhunesi / yii2-csc

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

    

mhunesi / yii2-csc example snippets


'components' => [
    'i18n' => [
        'translations' => [
            'csc' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'sourceLanguage' => 'en-US',
                'basePath' => '@mhunesi/csc/messages',
                'fileMap' => [
                    'csc' => 'csc.php',
                ],
            ],
        ],
    ],
],

'controllerMap' => [
    'migrate' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationPath' => [
            '@app/migrations',
            '@mhunesi/csc/migrations'
        ]
    ]
],

use mhunesi\csc\models\Country;
use mhunesi\csc\models\State;
use mhunesi\csc\models\City;

// Get all countries
$countries = Country::find()->all();

// Find a specific country by ISO2 code
$turkey = Country::find()->where(['iso2' => 'TR'])->one();

// Get all states of a country
$states = State::find()->where(['country_code' => 'TR'])->all();

// Access country's states through relation
$country = Country::findOne(1);
foreach ($country->states as $state) {
    echo $state->name . "\n";
    
    // Access state's cities through relation
    foreach ($state->cities as $city) {
        echo "  - " . $city->name . "\n";
    }
}

// Find cities by country
$turkishCities = City::find()
    ->where(['country_code' => 'TR'])
    ->all();

// Find a specific city
$istanbul = City::find()
    ->where(['name' => 'Istanbul', 'country_code' => 'TR'])
    ->one();
bash
php yii migrate