private function getDsnAttribute($name, $dsn)
{
if (preg_match('/' . $name . '=([^;]*)/', $dsn, $match)) {
return $match[1];
} else {
return null;
}
}
$this->getDsnAttribute('dbname', Yii::$app->getDb()->dsn);
$this->getDsnAttribute('dbname', static::getDb()->dsn);
$this->getDsnAttribute('dbname', ModelName::getDb()->dsn);
$this->getDsnAttribute('dbname', $this->db->dsn);
public function getAttrs()
{
return $this
->hasMany(Profile::className(), ['user_id' => 'id'])
->where('name = "name"')->union(
$this->hasMany(Profile::className(), ['user_id' => 'id'])->where('name = "surname"')
);
}
return $this->hasMany(User::className(), ['id' => 'u_id1'])
->viaTable('UserContacts', ['id' => 'u_id1'])->union($this->hasMany(User::className(), ['id' => 'u_id2'])
->viaTable('UserContacts', ['id' => 'u_id2']));
$user = User::find()->with('userBookmarks', 'userBookmarks.films' )->all();
public function getCountComments($period = false) {
$query = self::find();
if($this->post_id) {
$query->where(['post_id' => $this->post_id]);
}
if($this->type) {
$query->andWhere(['type' => $this->type]);
}
if($period == 'day') {
$query->andWhere('date_create>=CURDATE()');
}
return $query->count();
}
<a href="/comments/default/vote" class="upvote"> </a>
<script>
var ajax = {
voteUrl: '/comments/default/vote',
...
};
</script>
public function getCityList($cat_id) { // could be a static func as well
$models = \common\models\City::find()->where(['country_id' => $cat_id])->asArray()->all();
return ArrayHelper::map($models, 'id', 'name_ru','country_id');
}