Answer the question
In order to leave comments, you need to log in
Selection of posts through hasMany by passed label in url?
Good time !
In the url I pass the slug of the tag (from the slug I can get the id of the tag), by which I want to display all the posts attached to it
There is a "tags" label with tags, the table has such id | name | slug
columns I don't understand how to register dependencies using hasMany post_id | tag_id
to display my articles from the "statjiblog" table.
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
class Tags extends ActiveRecord
{
public function getPages()
{
return $this->hasMany(Statjiblog::className(), ['id' => 'post_id'])->viaTable('{{%statjiblogtags}}', ['tag_id' => 'id']);
}
}
public function actionPage($slug){
$model = Tags::find()->andWhere(['slug'=>$slug])->one();
foreach($model->pages as $page){
echo $page->title;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question