controller.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * This is the template for generating a CRUD controller class file.
  4. */
  5. use yii\db\ActiveRecordInterface;
  6. use yii\helpers\StringHelper;
  7. /* @var $this yii\web\View */
  8. /* @var $generator yii\gii\generators\crud\Generator */
  9. $controllerClass = StringHelper::basename($generator->controllerClass);
  10. $modelClass = StringHelper::basename($generator->modelClass);
  11. /* @var $class ActiveRecordInterface */
  12. $class = $generator->modelClass;
  13. $pks = $class::primaryKey();
  14. $urlParams = $generator->generateUrlParams();
  15. $actionParams = $generator->generateActionParams();
  16. $actionParamComments = $generator->generateActionParamComments();
  17. echo "<?php\n";
  18. ?>
  19. namespace <?= StringHelper::dirname(ltrim($generator->controllerClass, '\\')) ?>;
  20. use Yii;
  21. use <?= ltrim($generator->modelClass, '\\') ?>;
  22. use common\traits\Curd;
  23. use common\models\base\SearchModel;
  24. use <?= ltrim($generator->baseControllerClass, '\\') ?>;
  25. /**
  26. * <?= $modelClass . "\n" ?>
  27. *
  28. * Class <?= $controllerClass . "\n" ?>
  29. * @package <?= StringHelper::dirname(ltrim($generator->controllerClass, '\\')) . "\n" ?>
  30. */
  31. class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->baseControllerClass) . "\n" ?>
  32. {
  33. use Curd;
  34. /**
  35. * @var <?= $modelClass . "\n" ?>
  36. */
  37. public $modelClass = <?= $modelClass ?>::class;
  38. /**
  39. * 首页
  40. *
  41. * @return string
  42. * @throws \yii\web\NotFoundHttpException
  43. */
  44. public function actionIndex()
  45. {
  46. $searchModel = new SearchModel([
  47. 'model' => $this->modelClass,
  48. 'scenario' => 'default',
  49. 'partialMatchAttributes' => [], // 模糊查询
  50. 'defaultOrder' => [
  51. 'id' => SORT_DESC
  52. ],
  53. 'pageSize' => $this->pageSize
  54. ]);
  55. $dataProvider = $searchModel
  56. ->search(Yii::$app->request->queryParams);
  57. return $this->render('index', [
  58. 'dataProvider' => $dataProvider,
  59. 'searchModel' => $searchModel,
  60. ]);
  61. }
  62. }
粤ICP备19079148号