I
I
Ivan Lykov2017-10-03 18:39:43
Yii
Ivan Lykov, 2017-10-03 18:39:43

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();

You will call a separate post for each block. But then the title post is duplicated in small blocks... Here is a
picture 59d3ae884e01c161623767.png
Here is the code of the form
59d3aed79ee7c576224352.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Karachentsev, 2017-10-19
@Jhon_Light

Why do it so wildly.
In your request, do this:
Next provider:

$provider = new ActiveDataProvider([
            'query' => $ext,
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

In the view:
<?= \yii\widgets\ListView::widget([
            'dataProvider' => $provider,
            'id' => 'restaurants-news',
            'itemOptions' => ['class' => 'col-12 restaurants-news__item'],
            'itemView' => 'partials/_view',
        ]); ?>

And in the leafy view:
<?php if ($index === 1): ?>
// тут верстка для первой записи
<?php else: ?>
// тут для остальных
<?php endif; ?>

D
Dmitry Bay, 2017-10-03
@kawabanga

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 question

Ask a Question

731 491 924 answers to any question