S
S
Sergey Pugovkin2017-03-10 11:29:34
MySQL
Sergey Pugovkin, 2017-03-10 11:29:34

How to pass a connection to ActiveDataProvider?

The tag model has a link to articles through an intermediate table:

public function getArticles()
{
    return $this->hasMany(Article::className(), ['id' => 'articleId'])->viaTable(Relation::tableName(), ['tagId' => 'id']);
}

In the controller in the action I get the tag. How can I transfer this connection with articles to ActiveDataProvider?!
public function actionTag($tagSlug)
{
    $tag = Tag::find()->where(['slug' => $tagSlug])->one();
    $articles = Article::find()->???; // как тут быть???
    $provider = new ActiveDataProvider([
        'query' => $articles,
    ]);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2017-03-10
@Driver86

Do you need to get all articles with the $tagSlug tag?
Maybe so:

public function actionTag($tagSlug)
{
    $tag = Tag::find()->where(['slug' => $tagSlug])->one()->getArticles();
    $provider = new ActiveDataProvider([
        'query' => $tag,
    ]);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question