ArticleLangs.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\admin\controller\article;
  3. use app\common\controller\Backend;
  4. /**
  5. * 文章多语言信息管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class ArticleLangs extends Backend
  10. {
  11. /**
  12. * ArticleLangs模型对象
  13. * @var \app\admin\model\article\ArticleLangs
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\article\ArticleLangs;
  20. $this->view->assign("langlistList", $this->model->getLanglistList());
  21. }
  22. public function import()
  23. {
  24. parent::import();
  25. }
  26. /**
  27. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  28. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  29. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  30. */
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //当前是否为关联查询
  37. $this->relationSearch = false;
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  46. $list = $this->model
  47. ->where($where)
  48. ->order($sort, $order)
  49. ->paginate($limit);
  50. foreach ($list as $row) {
  51. $row->visible(['id', 'article_id', 'langlist', 'title', 'createtime']);
  52. }
  53. $result = array("total" => $list->total(), "rows" => $list->items());
  54. return json($result);
  55. }
  56. return $this->view->fetch();
  57. }
  58. /**
  59. * 添加
  60. */
  61. public function add()
  62. {
  63. if ($this->request->isPost()) {
  64. $params = $this->request->post("row/a");
  65. if ($this->model->where('article_id', $params['article_id'])->where('langlist', $params['langlist'])->find()) {
  66. $this->error(__('Same Language Data'));
  67. }
  68. }
  69. return parent::add();
  70. }
  71. /**
  72. * 添加
  73. */
  74. public function edit($ids = null)
  75. {
  76. if ($this->request->isPost()) {
  77. $params = $this->request->post("row/a");
  78. if ($this->model->where('id', '<>', $ids)->where('article_id', $params['article_id'])->where('langlist', $params['langlist'])->find()) {
  79. $this->error(__('Same Language Data'));
  80. }
  81. }
  82. return parent::edit($ids);
  83. }
  84. }