делаю связь в модели
Код: Выделить всё
public function getCatphotos()
{
return $this->hasOne(CatPhotos::className(), ['id' => 'cat_id']);
}
Код: Выделить всё
public function getCatphotos()
{
return $this->hasOne(CatPhotos::className(), ['id' => 'cat_id']);
}
Код: Выделить всё
/**
* init mmodel
*/
public function init()
{
$container = Yii::$container;
$this->_town = $container->get(TownAdapterInterface::class);
parent::init();
}
/**
* Город
* @return ActiveQuery
*/
public function getTown()
{
/** @var ActiveRecord $town */
$town = $this->_town;
$pk = $this->_town->getPk();
return $this->hasOne($town::className(), [$pk => 'town_id']);
}
Код: Выделить всё
TownAdapterInterface::class
Код: Выделить всё
get_class($object)