Answer the question
In order to leave comments, you need to log in
How to create multidimensional array to put it in dropDownList (yii2)?
There is a table of news and their categories.
request
find()->with(['category'])->orderBy(['position' => SORT_DESC])->all()
public function getCategory()
{
return $this->hasOne(NewsCategory::className(), ['id' => 'cat_id']);
}
'cat1' => [
1 => 'news_title1',
2 => 'In news_title2',
],
'cat2' => [
3 => 'news 3',
],
Answer the question
In order to leave comments, you need to log in
There are miracles, just wrote on the ball like this
and everything turned out)))
make
helper/CategoryDropDown with toArray(..) method
it returns an array using foreach as an example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question