/** * Lists all CmsClass models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => CmsClass::find(), 'pagination' => ['pageSize' => static::MAX_PAGE_SIZE], 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]); //递归处理 $dataProvider->models = General::recursiveObj($dataProvider->models, 0, 0, '', '<span class="bank"></span>', false); return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Updates an existing Customer model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { //$model = (new Customer(['scenario' => 'update']))->findOne($id); $model = $this->findModel($id); $model->setScenario('update'); if (Yii::$app->request->post()) { //时间转化 $post = General::dateTimeAsInt(Yii::$app->request->post(), 'Customer', ['birthday']); if ($model->load($post) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('update', ['model' => $model]); }
public function init() { //仅删除图片操作 if (Yii::$app->getRequest()->get('action', '') == 'del') { if (Yii::$app->getRequest()->get('filename', false)) { $fileName = Yii::$app->getRequest()->get('filename'); $path = Yii::getAlias('@webroot') . $fileName; if (is_file($path) && unlink($path)) { @unlink(str_replace('origin/', '', $path)); //尝试删除缓存 Json::encode(['status' => 0, 'msg' => Yii::t('uploadify', 'Delete File Success')]); } } Yii::$app->end(); } if (Yii::$app->getRequest()->isPost) { $this->initCsrf(); //临时关闭csrf并校验session id(客户端组件不支持) //风险控制 switch (false) { case $this->checkTimeOut(): echo Yii::t('uploadify', 'Upload timeout,Please refresh Page!'); break; case $this->checkSalt(): echo Yii::t('uploadify', 'Salt no pass,Invalid Data!'); break; case $this->checkSession(): echo Yii::t('uploadify', 'Session no pass,Invalid Data!'); break; default: //开始上传 //Yii::$app->getRequest()->post('iswatermark')//水印 $file = UploadedFile::getInstanceByName($this->fileData); $result = General::uploadToWebFilePath([$file], Yii::$app->getRequest()->post('dir')); if (is_array($result)) { echo $result['error']; //Json::encode(['status'=>0, 'msg'=>$result['error']]); } else { $pathInfo = $result; //调试 //file_put_contents(Yii::getAlias('@runtime').DIRECTORY_SEPARATOR.'test.txt', $pathInfo); } echo $pathInfo; //Json::encode(['status'=>0, 'msg'=>$pathInfo]); } Yii::$app->end(); } parent::init(); }
<div class="tab-content clearfix"> <div class="tab-pane active product-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <!-- <p> <?php echo Html::a(Yii::t('catalog', 'Create Product'), ['create'], ['class' => 'btn btn-success']); ?> </p> --> <?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'], 'name', 'shop_price:currency', 'sku', ['attribute' => 'category_id', 'value' => function ($model, $key, $index, $_this) { return $model->getRelatedRecords()['category']->name; }, 'filter' => ArrayHelper::map(General::recursiveObj(Category::find()->orderBy(['sort' => SORT_ASC])->all()), 'id', 'name')], ['header' => Yii::t('catalog', 'Shortcut'), 'format' => 'raw', 'value' => function ($model, $key, $index, $_this) { $str = ''; //$str .= '<a href="javascript:;" title="'.Yii::t('catalog', 'Is Del').'" data-id="'.$model->id.'" data-status="'.$model->is_del.'"><span class="label label-'.($model->is_del?'danger':'success').'"> </span></a> '; $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is Promote') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_promote . '"><span class="label label-' . ($model->is_promote ? 'success' : 'danger') . '"> </span></a> '; $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is Hot') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_hot . '"><span class="label label-' . ($model->is_hot ? 'success' : 'danger') . '"> </span></a> '; $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is New') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_new . '"><span class="label label-' . ($model->is_new ? 'success' : 'danger') . '"> </span></a> '; $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is Best') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_best . '"><span class="label label-' . ($model->is_best ? 'success' : 'danger') . '"> </span></a> '; $str .= '<a href="javascript:;" data-original-title="' . Yii::t('catalog', 'Is Free Shipping') . '" data-toggle="tooltip" data-id="' . $model->id . '" data-status="' . $model->is_free_shipping . '"><span class="label label-' . ($model->is_free_shipping ? 'success' : 'danger') . '"> </span></a> '; return $str; }], 'date_available:datetime', 'updated_at:datetime', ['attribute' => 'status', 'format' => 'html', 'value' => function ($model, $key, $index, $_this) { return '<span class="label label-' . ($model->status ? 'success' : 'danger') . '"> </span>'; }, 'filter' => [Product::PRODUCT_STATUS_ON => Yii::t('catalog', 'Status On'), Product::PRODUCT_STATUS_OFF => Yii::t('catalog', 'Status Off')]], ['class' => 'yii\\grid\\ActionColumn', 'header' => Yii::t('common', 'Opration')]]]); ?> </div>
use yii\helpers\Html; //use yii\widgets\ActiveForm; use yii\bootstrap\ActiveForm; use yii\helpers\ArrayHelper; use common\components\helpers\General; use common\models\catalog\Category; use backend\components\uploadify\UploadifyWidget; use backend\components\ueditor\UeditorWidget; /* @var $this yii\web\View */ /* @var $model common\models\catalog\Category */ /* @var $form yii\widgets\ActiveForm */ if ($model->isNewRecord) { $model->status = true; } $parentList = ArrayHelper::merge([0 => Yii::t('catalog', 'Top Category')], ArrayHelper::map(General::recursiveObj(Category::find()->orderBy(['sort' => SORT_ASC])->all()), 'id', 'name')); ?> <div class="row category-form"> <div class="col-md-1"></div> <div class="col-md-12 col-lg-6"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'parent_id')->dropDownList($parentList); ?>
use common\components\helpers\General; use common\models\catalog\Category; use common\models\catalog\Brand; use backend\assets\DatePickerAsset; /* @var $this yii\web\View */ /* @var $model common\models\catalog\Product */ /* @var $form yii\widgets\ActiveForm */ //加载一插件 DatePickerAsset::register($this); //使用插件 $this->registerJs("\n\t\$('#product-promote_start_date, #product-promote_end_date').datepicker({\n language: '" . Yii::$app->language . "',//使用当前语言\n\t format: 'yyyy/mm/dd'\n\t});\n"); $model->promote_start_date = Yii::$app->getFormatter()->asDate($model->promote_start_date, 'yyyy/MM/dd'); //与js配合 $model->promote_end_date = Yii::$app->getFormatter()->asDate($model->promote_end_date, 'yyyy/MM/dd'); //与js配合 $cateList = ArrayHelper::map(General::recursiveObj(Category::find()->orderBy(['sort' => SORT_ASC])->all()), 'id', 'name'); $brandList = ArrayHelper::map(Brand::find()->orderBy(['sort' => SORT_ASC])->all(), 'id', 'name'); ?> <!-- 导航 --> <div id="product_nav"> <ul> <li><a href="#home"><?php echo Yii::t('catalog', 'Base'); ?> </a></li> <li><a href="#declare"><?php echo Yii::t('catalog', 'Declare'); ?> </a></li> <li><a href="#price"><?php
<div class="tab-pane active category-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <!-- <p> <?php echo Html::a(Yii::t('catalog', 'Create Category'), ['create'], ['class' => 'btn btn-success']); ?> </p> --> <?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'], 'name', ['attribute' => 'parent_id', 'filter' => ArrayHelper::merge([0 => Yii::t('catalog', 'Top Category')], ArrayHelper::map(General::recursiveObj(Category::find()->orderBy(['sort' => SORT_ASC])->all()), 'id', 'name')), 'value' => function ($model, $key, $index, $_this) { if (!$model->parent_id) { return Yii::t('catalog', 'Top Category'); } else { return $model->getRelatedRecords()['mySelf']->name; } }], ['attribute' => 'top', 'filter' => [Category::CATEGORY_IS_TOP => Yii::t('catalog', 'Is Top'), Category::CATEGORY_NOT_TOP => Yii::t('catalog', 'Not Top')], 'value' => function ($model, $key, $index, $_this) { return $model->top ? Yii::t('catalog', 'Is Top') : Yii::t('catalog', 'Not Top'); }], ['attribute' => 'status', 'filter' => [Category::CATEGORY_STATUS_ON => Yii::t('catalog', 'Status On'), Category::CATEGORY_STATUS_OFF => Yii::t('catalog', 'Status Off')], 'value' => function ($model, $key, $index, $_this) { return $model->status ? Yii::t('catalog', 'Status On') : Yii::t('catalog', 'Status Off'); }], ['attribute' => 'sort', 'filter' => false], ['attribute' => 'updated_at', 'format' => 'datetime', 'filter' => false], ['class' => 'yii\\grid\\ActionColumn', 'header' => Yii::t('common', 'Opration')]]]); ?> </div> </div>
use yii\helpers\ArrayHelper; use common\components\helpers\General; use common\models\cms\CmsClass; use yii\base\Object; /* @var $this yii\web\View */ /* @var $model common\models\cms\CmsClass */ /* @var $form yii\widgets\ActiveForm */ if ($model->isNewRecord) { $model->status = true; $model->order = 10; } //指定了父级栏目 if (isset($id) && $id !== false) { $model->parent_id = $id; } $parentIds = ArrayHelper::merge(['0' => Yii::t('cms', 'Top Class')], ArrayHelper::map(General::recursiveObj(CmsClass::find()->orderBy(['order' => SORT_ASC])->all()), 'id', 'name')); ?> <div class="row cms-class-form"> <div class="col-md-1"></div> <div class="col-md-12 col-lg-6"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'type')->dropDownList((new CmsClass())->cmsType); ?> <?php echo $form->field($model, 'parent_id')->dropDownList($parentIds);