public function actionPhotos($id) { if (!($model = Category::findOne($id))) { return $this->redirect(['/admin/' . $this->module->id]); } return $this->render('photos', ['model' => $model]); }
public function dbInstall() { $db = Yii::$app->db; $tableOptions = null; if ($db->driverName === 'mysql') { $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=MyISAM'; } $db->createCommand()->createTable(Category::tableName(), ['file_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'file' => Schema::TYPE_STRING . '(255) NOT NULL', 'size' => Schema::TYPE_INTEGER . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'downloads' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'order_num' => Schema::TYPE_INTEGER], $tableOptions)->execute(); $db->createCommand()->createIndex('slug', Category::tableName(), 'slug', true)->execute(); }
public function photos($options = []) { if (!$this->_photos) { $this->_photos = []; $query = Photo::find()->where(['class' => Category::className(), 'item_id' => $this->id])->sort(); if (!empty($options['where'])) { $query->andFilterWhere($options['where']); } $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : []]); foreach ($this->_adp->models as $model) { $this->_photos[] = new PhotoObject($model); } } return $this->_photos; }
<?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>
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.'; }
public function down() { $this->dropTable(models\Admin::tableName()); $this->dropTable(models\LoginForm::tableName()); $this->dropTable(models\Module::tableName()); $this->dropTable(models\Photo::tableName()); $this->dropTable(models\Setting::tableName()); $this->dropTable(Carousel::tableName()); $this->dropTable(catalog\models\Category::tableName()); $this->dropTable(catalog\models\Item::tableName()); $this->dropTable(article\models\Category::tableName()); $this->dropTable(article\models\Item::tableName()); $this->dropTable(Feedback::tableName()); $this->dropTable(File::tableName()); $this->dropTable(gallery\models\Category::tableName()); $this->dropTable(Guestbook::tableName()); $this->dropTable(News::tableName()); $this->dropTable(Page::tableName()); $this->dropTable(Subscriber::tableName()); $this->dropTable(History::tableName()); $this->dropTable(Text::tableName()); }
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; }