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/ */
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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.