/** * Updates an existing Game model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $categories = GameCategory::find()->all(); $model = $this->findModel($id); if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'categories' => $categories]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = GameCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getCategory() { return $this->hasOne(GameCategory::className(), ['id' => 'category_id']); }
public static function getActiveGamesByCategorySlug($slug) { $gameCat = GameCategory::find()->where(['slug' => $slug])->one(); if ($gameCat != null) { return Game::find()->where(['status' => Game::STATUS_IN_USE, 'category_id' => $gameCat->id])->all(); } return null; }
use common\models\Game; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\GameSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('common', 'Games'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="game-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('backend', 'Create {modelClass}', ['modelClass' => Yii::t('common', 'Game')]), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'category_id', 'value' => function ($model) { return $model->category ? $model->category->title : null; }, 'filter' => ArrayHelper::map(\common\models\GameCategory::find()->all(), 'id', 'title')], 'name', 'short', ['attribute' => 'thumbnail', 'format' => 'html', 'value' => function ($model) { return Html::img(Yii::$app->glide->createSignedUrl(['glide/index', 'path' => $model->thumbnail_path, 'w' => 150], true), ['class' => 'img-responsive']); }], ['attribute' => 'attr', 'value' => function ($model) { return ArrayHelper::getValue(Game::getAttr(), $model->attr); }, 'filter' => Game::getAttr()], ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => [Yii::t('common', 'Not Used'), Yii::t('common', 'In Use')]], ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'is_recommend', 'enum' => [Yii::t('common', 'Not'), Yii::t('common', 'Yes')]], 'sort', ['class' => 'yii\\grid\\ActionColumn']], 'layout' => "{items}\n{summary}\n{pager}"]); ?> </div>
$this->endBlock(); ?> <div class="container content"> <div class="row magazine-page"> <!-- Begin Content --> <div class="col-md-9"> <div class="headline"><h3>游戏列表</h3></div> <div class="game-list" id="gameList"> <div class="game-list-select" id="gameListSelect"> <p data-key="game_type"> <strong>游戏类型:</strong> <a href="javascript:;" class="focus" data-target="0">不限</a> <?php foreach (\common\models\GameCategory::find()->all() as $gameCat) { ?> <?php echo Html::a($gameCat->title, ['index', 'GameSearch[category_id]' => $gameCat->id]); ?> <?php } ?> </p> <p class="game-list-select-last" data-key="pinyin"> <strong>字母排序:</strong> <a href="javascript:;" class="focus" data-target="0">不限</a> <?php echo Html::a('ABCDE', ['index', 'GameSearch[short]' => 'a,b,c,d,e']); ?>
<?php use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\widgets\DetailView; use common\models\Game; /* @var $this yii\web\View */ /* @var $model common\models\Game */ $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => Yii::t('common', 'Games'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="game-view"> <p> <?php echo Html::a(Yii::t('backend', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'), 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => [['attribute' => 'category_id', 'value' => \common\models\GameCategory::find()->where(['id' => $model->category_id])->one()['title']], 'name', 'description:ntext', 'short', 'api_key', 'factory', 'cname', ['attribute' => 'thumbnail', 'format' => 'html', 'value' => Html::img(Yii::$app->glide->createSignedUrl(['glide/index', 'path' => $model->thumbnail_path], true), ['class' => 'img-responsive'])], ['attribute' => 'bg_image', 'format' => 'html', 'value' => Html::img(Yii::$app->glide->createSignedUrl(['glide/index', 'path' => $model->bg_image_path], true), ['class' => 'img-responsive'])], 'coin', 'coin_rate', 'game_web_url:url', 'game_bbs_url:url', 'api_secret', 'api_server', 'api_play', 'api_pay', 'api_check', 'api_order', 'q', ['attribute' => 'attr', 'value' => ArrayHelper::getValue(Game::getAttr(), $model->attr)], ['attribute' => 'is_recommend', 'value' => \common\models\Game::IS_RECOMMEND_YES == $model->is_recommend ? Yii::t('common', 'Yes') : Yii::t('common', 'Not')], 'slug', 'created_at:datetime', 'updated_at:datetime', ['attribute' => 'status', 'value' => \common\models\Game::STATUS_IN_USE == $model->status ? Yii::t('common', 'In Use') : Yii::t('common', 'Not Used')], 'sort']]); ?> </div>
/** * Finds the GameCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return GameCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = GameCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getGameCategories() { return $this->hasMany(GameCategory::className(), ['parent_id' => 'id']); }