CommentController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2017-10-03 22:03
  7. */
  8. namespace backend\controllers;
  9. use Yii;
  10. use common\services\CommentServiceInterface;
  11. use backend\actions\ViewAction;
  12. use backend\actions\UpdateAction;
  13. use backend\actions\IndexAction;
  14. use backend\actions\DeleteAction;
  15. /**
  16. * Comment management
  17. * - data:
  18. * table comment
  19. * -description:
  20. * article's comment
  21. *
  22. * Class CommentController
  23. * @package backend\controllers
  24. */
  25. class CommentController extends \yii\web\Controller
  26. {
  27. /**
  28. * @auth
  29. * - item group=内容 category=评论 description-get=列表 sort=320 method=get
  30. * - item group=内容 category=评论 description-get=查看 sort=321 method=get


  31. * - item group=内容 category=评论 description=修改 sort-get=322 sort-post=323 method=get,post

  32. * - item group=内容 category=评论 description-post=删除 sort=324 method=post


  33. * @return array
  34. * @throws \yii\base\InvalidConfigException
  35. */
  36. public function actions()
  37. {
  38. /** @var CommentServiceInterface $service */
  39. $service = Yii::$app->get(CommentServiceInterface::ServiceName);
  40. return [
  41. 'index' => [
  42. 'class' => IndexAction::className(),
  43. 'data' => function(array $query)use($service){
  44. $result = $service->getList($query);
  45. return [
  46. 'dataProvider' => $result['dataProvider'],
  47. 'searchModel' => $result['searchModel'],
  48. ];
  49. }
  50. ],
  51. 'view-layer' => [
  52. 'class' => ViewAction::className(),
  53. 'data' => function($id)use($service){
  54. return [
  55. 'model' => $service->getDetail($id),
  56. ];
  57. },
  58. ],
  59. 'update' => [
  60. 'class' => UpdateAction::className(),
  61. 'doUpdate' => function($id, array $postData)use($service){
  62. return $service->update($id, $postData);
  63. },
  64. 'data' => function($id, $updateResultModel)use($service){
  65. $model = $updateResultModel === null ? $service->getDetail($id) : $updateResultModel;
  66. return [
  67. 'model' => $model,
  68. ];
  69. },
  70. ],
  71. 'delete' => [
  72. 'class' => DeleteAction::className(),
  73. 'doDelete' => function($id)use($service){
  74. return $service->delete($id);
  75. },
  76. ],
  77. ];
  78. }
  79. }