LatestNews.php 776 Bytes
<?php

namespace frontend\modules\news\widgets\LatestNews;

use frontend\modules\news\models\Article;

/**
 * Class LatestNews
 *
 * @package frontend\modules\news\widgets\LatestNews
 * @author FilamentV <vortex.filament@gmail.com>
 * @copyright (c), Thread
 */
class LatestNews extends \thread\app\base\widgets\Widget
{
    public $limit = 10;
    /**
     * @var null
     */
    protected $items = null;

    /**
     *
     */
    public function init()
    {
        parent::init();

        $this->items = Article::find()->limit($this->limit)->all();

    }

    /**
     *
     */
    public function run()
    {
        if ($this->items != null) {
            return $this->render('index', [
                'articles' => $this->items
            ]);
        }
    }
}