Agreement.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. use app\common\model\Page as PageModel;
  5. use app\common\library\Service;
  6. class Agreement extends Frontend
  7. {
  8. protected $noNeedLogin = '*';
  9. protected $noNeedRight = '*';
  10. protected $layout = '';
  11. // 查询协议
  12. public function index(){
  13. $keyword = $this->request->param('keyword');
  14. if ($keyword && !is_numeric($keyword)) {
  15. $page = PageModel::getByDiyname($keyword);
  16. } else {
  17. $id = $keyword ? $keyword : $this->request->param('id', '');
  18. $page = PageModel::get($id);
  19. }
  20. // 如果没有指定页面或页面不存在,获取第一个正常状态的页面
  21. if (empty($page)) {
  22. $page = PageModel::where('status', 'normal')->order('id asc')->find();
  23. }
  24. if (!empty($page)) {
  25. $page->setInc('views');
  26. $image = $page->getData('image');
  27. $fields = explode(',', 'id,title,content,image,description,status,createtime');
  28. $pageData = array_intersect_key($page->toArray(), array_flip($fields));
  29. $pageData['content'] = Service::formatSourceTpl($pageData['content']);
  30. $pageData['image'] = $image ? cdnurl($image, true) : $image;
  31. // 分配变量到模板
  32. $this->view->assign('page', $pageData);
  33. return $this->view->fetch();
  34. } else {
  35. $this->error('未找到页面内容');
  36. }
  37. }
  38. }