/** * Finds the Flag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Flag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Flag::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> </p> --> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'options' => ['class' => 'grid-view box-body table-responsive no-padding'], 'tableOptions' => ['class' => 'table table-hover table-striped table-bordered'], 'headerRowOptions' => [], 'footerRowOptions' => [], 'showHeader' => true, 'showFooter' => false, 'layout' => "{summary}\n{errors}\n{items}\n{pager}", 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'title', 'format' => 'raw', 'value' => function ($model) { $length = Yii::$app->params['config']['config_site_title_length']; $options = ['style' => '']; Html::addCssStyle($options, ['color' => $model->colorval, 'font-weight' => $model->boldval]); $title = '<span title="' . $model->title . '" style="' . $options['style'] . '">' . StringHelper::truncate($model->title, $length) . '</span>'; return Html::a($title, ['update', 'id' => $model->id], ['data-pjax' => '0']); }], ['attribute' => 'column_id', 'filter' => ArrayHelper::map(Column::find()->where(['type' => Column::CMS_TYPE_IMG])->alive()->all(), 'id', 'name'), 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) { return $model->column->name; }], ['attribute' => 'flag', 'filter' => ArrayHelper::map(Flag::find()->orderBy('order')->all(), 'id', 'name'), 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) { return $model->flagModel->flag; }], 'hits', ['attribute' => 'status', 'format' => 'html', 'filter' => [Img::STATUS_YES => Yii::t('cms', 'Yes'), Img::STATUS_NO => Yii::t('cms', 'No')], 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) { $on = Html::a('<small class="label bg-green">' . Yii::t('common', 'Yes') . '</small>', ['switch-status', 'id' => $model->id], ['title' => Yii::t('cms', 'Update Status'), 'data-pjax' => '0']); $off = Html::a('<small class="label bg-red">' . Yii::t('common', 'No') . '</small>', ['switch-status', 'id' => $model->id], ['title' => Yii::t('cms', 'Update Status'), 'data-pjax' => '0']); return $model->status ? $on : $off; }], 'created_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {delete}', 'header' => Yii::t('common', 'Opration')]]]); ?> <?php Pjax::end(); ?> </div> </div> </div>
<?php //局部布局 echo $form->field($model, 'title', ['horizontalCssClasses' => ['wrapper' => 'col-sm-8'], 'inputTemplate' => '<div class="input-group">{input}<span class="input-group-addon"><span class="color title-colorpicker" title="' . Yii::t('cms', 'Title Color') . '"><i style="background-color: rgb(0, 170, 187);"></i></span> <span class="blod" title="' . Yii::t('cms', 'Title Bold') . '"><i class="fa fa-bold"></i></span> <span class="clear" title="' . Yii::t('cms', 'Clear') . '"><i class="fa fa-eraser"></i></span></span></div>'])->hint('<i class="fa fa-info-circle"></i> ' . Yii::t('cms', 'Title is required'), ['class' => 'help-block error-none'])->textInput(['maxlength' => true, 'style' => !empty($titleOptions) ? $titleOptions['style'] : '']); //直接对长度限制 ?> <?php echo Html::activeHiddenInput($model, 'colorval'); ?> <?php echo Html::activeHiddenInput($model, 'boldval'); ?> <?php echo $form->field($model, 'flag')->inline()->checkboxList(ArrayHelper::map(Flag::find()->orderBy('order')->alive()->all(), 'flag', 'name')); ?> <?php echo $form->field($model, 'file_type')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'language')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'accredit')->textInput(['maxlength' => true]); ?> <?php
/** * 一对一 */ public function getFlagModel() { $this->flag = explode(',', $this->flag); $models = Flag::find()->where(['in', 'flag', $this->flag])->all(); $names = ArrayHelper::map($models, 'name', 'id'); $this->flag = implode(',', array_keys($names)); return $this; }