1. Go to this page and download the library: Download akavov/yii2-countries 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/ */
akavov / yii2-countries example snippets
php composer.phar
namespace ict\posts\common\models;
use Yii;
use yii\db\Expression;
use yii\behaviors\TimestampBehavior;
use creocoder\taggable\TaggableBehavior;
use akavov\countries\components\CountriesBehavior;
/**
* This is the model class for table "{{%post}}".
* ...
* @property string $countryValues
*/
class Post extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%post}}';
}
public function behaviors()
{
return [
...
[
'class' => CountriesBehavior::className(),
],
...
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
...
['countryValues', 'safe'],
...
];
}
public function transactions()
{
return [
self::SCENARIO_DEFAULT => self::OP_ALL,
];
}
public function getCountries()
{
return $this->hasMany(Country::className(), ['id' => 'country_id'])
->viaTable('{{%post_country_assn}}', ['post_id' => 'id']);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.