Answer the question
In order to leave comments, you need to log in
How to display the latest news with different image sizes?
Good day folks, I have a question?
Judging from the name, you can already understand
I store 5 entries on the main one, one of the entries is a large picture, a description and a couple more goodies. Next to it are 4 other entries.
I do something like this in code
$ext = extrime::find()->select('id, title, excerpt, mini_img, id_category, id_user')->limit(5)->all();
$ext_one = extrime::find()->select('id, title, excerpt, mini_img mid_category, id_user')->limit(1)->all();
Answer the question
In order to leave comments, you need to log in
Why do it so wildly.
In your request, do this:
Next provider:
$provider = new ActiveDataProvider([
'query' => $ext,
'pagination' => [
'pageSize' => 10,
],
]);
<?= \yii\widgets\ListView::widget([
'dataProvider' => $provider,
'id' => 'restaurants-news',
'itemOptions' => ['class' => 'col-12 restaurants-news__item'],
'itemView' => 'partials/_view',
]); ?>
<?php if ($index === 1): ?>
// тут верстка для первой записи
<?php else: ?>
// тут для остальных
<?php endif; ?>
1) class names are usually written with a capital letter. extrime -> Extrime
2) When you query ->all() without specifying indexes, you get an array like
$models = [
0=>'Model1',
1=>'Model2'
]
What does it mean if there is something in the array , then you can access the first element via $ext[0] .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question