public function actionTypedel($id) { $model = GoodsType::findOne($id); if ($model->delete()) { Attribute::deleteAll('type_id = :type_id', [':type_id' => $id]); Yii::$app->getSession()->setFlash('info', '操作删除成功!'); return $this->redirect(['typelist']); } }
/** * Finds the GoodsType model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return GoodsType the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = GoodsType::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> ')" value=" 搜索 " class="button"> </form> </div> <?php echo Html::beginForm(['deleteall']); ?> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'showFooter' => true, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn', 'name' => 'id', 'footer' => Html::button('批量删除', ['class' => 'btn btn-danger', 'onclick' => 'submits()']), 'options' => ['width' => 70]], 'attr_id', ['header' => Html::a('商品类型', 'javascript:;'), 'content' => function ($model) { return GoodsType::findOne($model->cat_id)->cat_name; }], 'attr_name', ['header' => Html::a('录入方式', 'javascript:;'), 'content' => function ($model) { $typeList = ['0' => '手工录入', '1' => '从列表中选择', '2' => '多行文本框']; return $typeList[$model->attr_input_type]; }], ['attribute' => 'attr_values', 'value' => function ($model) { $content = str_replace("\r\n", ', ', $model->attr_values); return Functions::truncate_utf8_string($content, 28); }, 'options' => ['width' => 430]], ['attribute' => 'sort_order', 'value' => function ($model) { return $model->sort_order; }, 'options' => ['width' => 70]], ['class' => 'yii\\grid\\ActionColumn', 'header' => Html::a('操作', 'javascript:void(0);'), 'template' => '{update} {delete} {deletes}']]]); ?> <?php Pjax::end(); ?> <?php echo Html::endForm();
/** * 获取一个类型分组 ( 表单页面 ) * @param int $cat_id 商品类型id * @param int $attr_group_id */ public function actionAttrgroup($cat_id, $attr_group_id = 0) { $attr_group = GoodsType::findOne($cat_id)->attr_group; if (!empty($attr_group)) { // 组合成option下拉 $attr_group = explode("\r\n", $attr_group); $option = ''; foreach ($attr_group as $key => $val) { $selected = $attr_group_id == $key ? 'selected' : ''; $option .= "<option {$selected} value='{$key}'>{$val}</option>"; } exit($option); } }