Answer the question
In order to leave comments, you need to log in
Yii2 -> work 2 or 100 sites from one directory?
There was a need to organize the work of several sites from one directory
In the database, an identifier was added to each table in the form of a domain, output to the controller through
->where(['status' => '1','domain' => preg_replace("/^www./","",$_SERVER['HTTP_HOST'])])
Answer the question
In order to leave comments, you need to log in
Create scope :
class MyActiveQuery extends \yii\db\ActiveQuery
{
public function init()
{
$modelClass = $this->modelClass;
$tableName = $modelClass::tableName();
$domainName = preg_replace("/^www./","",$_SERVER['HTTP_HOST']);
$this->andWhere([$tableName.'.domain' => $domainName]);
parent::init();
}
}
class MyActiveRecord extends \yii\db\ActiveRecord
{
public static function find()
{
return new MyActiveQuery(get_called_class());
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question