S
S
SidorKovpak2016-09-28 15:28:43
PHP
SidorKovpak, 2016-09-28 15:28:43

Activerecord limit selection of news by widget?

Good afternoon.
Lack of experience in writing database queries.
There is a news site on (yii2) where you need to display a certain number of news for each widget.
You need to select all entries where widget = 2(NEWS_CARD_WIDGET) and category = 1($categoryId), sort them by date so that the latest entries are at the top and take the first 5 items from this.
What now:

News::find()->published()->where(['widget' => News::NEWS_CARD_WIDGET, 'category' => $categoryId])->orderBy(['created_at' => SORT_DESC])->limit(5);

published() = post date is less than current date in linx
There is nothing in the selection.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Velichko, 2016-10-02
@ForestEsprit

- var data = { "items" : [ { "articles": [ { "title": "Заголовок 2", }, { "title": "Заголовок 1" }  ] }  ] };

p= data.items[0].articles[0].title

In general, such data is usually output in cycles.

A
Albert Kazan, 2016-09-29
@Farrien

Of course, I may be very wrong, but is it acceptable to set the same keys in JSON?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question