/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MGoodscat::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'value' => $this->value]); $query->andFilterWhere(['like', 'cat', $this->cat]); return $dataProvider; }
<?php if (Yii::$app->user->isGuest) { $isAdmin = false; $isMember = false; } else { if (Yii::$app->user->identity->role == 1) { $isAdmin = true; $isMember = false; } else { $isAdmin = false; $isMember = true; } } //get goods cat $goodscat = MGoodscat::find()->all(); NavBar::begin(['brandLabel' => empty($about->com_name) ? "" : $about->com_name, 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]); /* $menuItems = [ ['label' => '首页', 'url' => ['/site/index']], ['label' => '关于', 'url' => ['/site/about']], ['label' => '联系', 'url' => ['/site/contact']], ]; if (Yii::$app->user->isGuest) { $menuItems[] = ['label' => '注册', 'url' => ['/site/signup']]; $menuItems[] = ['label' => '登录', 'url' => ['/site/login']]; } else { //if (Yii::$app->user->identity->role == 1) { $menuItems[] = [
<?php use yii\helpers\Html; use yii\grid\GridView; use app\models\MGoods; use app\models\MGoodsSearch; use app\models\MGoodscat; /* @var $this yii\web\View */ /* @var $searchModel app\models\MGoodsSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ use app\models\U; $goods_kind = $_GET["goods_kind"]; $goodscat = MGoodscat::findOne(['value' => $goods_kind]); $this->title = '商品列表'; ?> <div class="mgoods-index"> <h4><?php echo Html::encode($this->title); ?> | <?php echo empty($goodscat) ? '' : $goodscat->cat; ?> </h4> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <!-- <p> <//?= Html::a('新增商品', ['create'], ['class' => 'btn btn-success']) ?>
/** * Finds the MGoodscat model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MGoodscat the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MGoodscat::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
static function getGoodsKindOption($key = null) { $goodscat = MGoodscat::find()->asArray()->all(); foreach ($goodscat as $gc) { $value = $gc['value']; $arr[$value] = "{$gc['cat']}"; } return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : ''); }