You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.9 KiB

  1. <?php
  2. namespace backend\controllers;
  3. use common\models\ars\Config;
  4. use Yii;
  5. use common\models\ars\Attribute;
  6. use common\models\searchs\AttributeSearch;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. /**
  11. * AttributeController implements the CRUD actions for Attribute model.
  12. */
  13. class AttributeController extends Controller
  14. {
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function behaviors()
  19. {
  20. return [
  21. 'verbs' => [
  22. 'class' => VerbFilter::className(),
  23. 'actions' => [
  24. 'delete' => ['POST'],
  25. ],
  26. ],
  27. ];
  28. }
  29. /**
  30. * Lists all Attribute models.
  31. * @return mixed
  32. */
  33. public function actionIndex()
  34. {
  35. $searchModel = new AttributeSearch();
  36. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  37. return $this->render('index', [
  38. 'searchModel' => $searchModel,
  39. 'dataProvider' => $dataProvider,
  40. 'columns' => $searchModel->columns()
  41. ]);
  42. }
  43. /**
  44. * Displays a single Attribute model.
  45. * @param integer $id
  46. * @return mixed
  47. * @throws NotFoundHttpException if the model cannot be found
  48. */
  49. public function actionView($id)
  50. {
  51. return $this->render('view', [
  52. 'model' => $this->findModel($id),
  53. ]);
  54. }
  55. /**
  56. * Creates a new Attribute model.
  57. * If creation is successful, the browser will be redirected to the 'view' page.
  58. * @return mixed
  59. */
  60. public function actionCreate()
  61. {
  62. $model = new Attribute();
  63. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  64. return $this->redirect('index');
  65. }
  66. return $this->render('create', [
  67. 'model' => $model,
  68. ]);
  69. }
  70. /**
  71. * Updates an existing Attribute model.
  72. * If update is successful, the browser will be redirected to the 'view' page.
  73. * @param integer $id
  74. * @return mixed
  75. * @throws NotFoundHttpException if the model cannot be found
  76. */
  77. public function actionUpdate($id)
  78. {
  79. $model = $this->findModel($id);
  80. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  81. return $this->redirect('index');
  82. }
  83. return $this->render('update', [
  84. 'model' => $model,
  85. ]);
  86. }
  87. /**
  88. * Deletes an existing Attribute model.
  89. * If deletion is successful, the browser will be redirected to the 'index' page.
  90. * @param integer $id
  91. * @return mixed
  92. * @throws NotFoundHttpException if the model cannot be found
  93. */
  94. public function actionDelete($id)
  95. {
  96. $this->findModel($id)->delete();
  97. return $this->redirect(['index']);
  98. }
  99. /**
  100. * Finds the Attribute model based on its primary key value.
  101. * If the model is not found, a 404 HTTP exception will be thrown.
  102. * @param integer $id
  103. * @return Attribute the loaded model
  104. * @throws NotFoundHttpException if the model cannot be found
  105. */
  106. protected function findModel($id)
  107. {
  108. if (($model = Attribute::findOne($id)) !== null) {
  109. return $model;
  110. }
  111. throw new NotFoundHttpException('The requested page does not exist.');
  112. }
  113. /**
  114. * @author iron
  115. * 文件导出
  116. */
  117. public function actionExport()
  118. {
  119. $searchModel = new attributeSearch();
  120. $params = Yii::$app->request->queryParams;
  121. if ($params['page-type'] == 'all') {
  122. $dataProvider = $searchModel->allData($params);
  123. } else {
  124. $dataProvider = $searchModel->search($params);
  125. }
  126. \iron\widget\Excel::export([
  127. 'models' => $dataProvider->getModels(),
  128. 'format' => 'Xlsx',
  129. 'asAttachment' => true,
  130. 'fileName' => 'Attributes' . "-" . date('Y-m-d H/i/s', time()),
  131. 'columns' => $searchModel->columns()
  132. ]);
  133. }
  134. }