Answer the question
In order to leave comments, you need to log in
Yii2 empty array via sqldataprovider what is the reason?
Good afternoon everyone! help someone with what you can))
Actually, the problem is this through sql data provider I make a request (in phpmyadmin everything is correct) in yii2 returns an empty array
public function getBeforeArticles($n)
{
return new SqlDataProvider([
'sql'=>"select * from ( select * from Articles where id <= :id ORDER BY id DESC) ar LIMIT :n",
'params' =>['id' => [$this->id],'n'=> [$n]], ]);
}
Perhaps my solution is fundamentally wrong, but so far I have not found another, the task is to get materials whose id is less than the current one by $ n
Answer the question
In order to leave comments, you need to log in
I don't quite understand the problem, but if
the task is to get materials whose id is less than the current one by $nthen you can use the Articles model:
$current_id = $this->id;
$n = 10;
$articles = Articles::find()
->where(['<', 'id', ($current_id - $n)])
->orderBy('id DESC')
->limit(10) // Не понятно как у вас там должен лимит работать, пусть будет 10
->all();
foreach($articles as $article) {
echo $article->id;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question