public function insertGallery() { if (gallery\models\Category::find()->count()) { return '`<b>' . gallery\models\Category::tableName() . '</b>` table is not empty, skipping...'; } $this->db->createCommand('TRUNCATE TABLE `' . gallery\models\Category::tableName() . '`')->query(); $album1 = new gallery\models\Category(['title' => 'Album 1', 'image' => '/uploads/gallery/album-1.jpg', 'order_num' => 2]); $album1->makeRoot(); $this->attachSeo($album1, 'Album 1 H1', 'Extended Album 1 title'); $this->attachPhotos($album1, ['/uploads/photos/album-1-9.jpg', '/uploads/photos/album-1-8.jpg', '/uploads/photos/album-1-7.jpg', '/uploads/photos/album-1-6.jpg', '/uploads/photos/album-1-5.jpg', '/uploads/photos/album-1-4.jpg', '/uploads/photos/album-1-3.jpg', '/uploads/photos/album-1-2.jpg', '/uploads/photos/album-1-1.jpg']); $album2 = new gallery\models\Category(['title' => 'Album 2', 'image' => '/uploads/gallery/album-2.jpg', 'order_num' => 1]); $album2->makeRoot(); $this->attachSeo($album2, 'Album 2 H1', 'Extended Album 2 title'); return 'Gallery data inserted.'; }
<?php } ?> </div> </div> </div> <div class="container"> <div class="row"> <div class="col col-9 news-content news-block"> <h2>Свежие фотографии</h2> <div class="container"> <div class="row"> <?php foreach (\yii\easyii\modules\gallery\models\Category::find()->limit(4)->all() as $gallery) { ?> <div class="col col-2"> <img src="<?php echo $gallery->image; ?> " style="width: 150px;"/> <?php echo Html::a($gallery->title, ['site/gallery', 'slug' => $gallery->slug]); ?> </div> <?php } ?> </div> </div>
private function findCategory($id_slug) { $category = Category::find()->where(['or', 'category_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Category::STATUS_ON)->one(); return $category ? new CategoryObject($category) : null; }