12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace app\index\controller;
- use app\common\controller\Frontend;
- use app\common\model\Page as PageModel;
- use app\common\library\Service;
- class Agreement extends Frontend
- {
- protected $noNeedLogin = '*';
- protected $noNeedRight = '*';
- protected $layout = '';
- // 查询协议
- public function index(){
- $keyword = $this->request->param('keyword');
- if ($keyword && !is_numeric($keyword)) {
- $page = PageModel::getByDiyname($keyword);
- } else {
- $id = $keyword ? $keyword : $this->request->param('id', '');
- $page = PageModel::get($id);
- }
-
- // 如果没有指定页面或页面不存在,获取第一个正常状态的页面
- if (empty($page)) {
- $page = PageModel::where('status', 'normal')->order('id asc')->find();
- }
-
- if (!empty($page)) {
- $page->setInc('views');
- $image = $page->getData('image');
- $fields = explode(',', 'id,title,content,image,description,status,createtime');
- $pageData = array_intersect_key($page->toArray(), array_flip($fields));
- $pageData['content'] = Service::formatSourceTpl($pageData['content']);
- $pageData['image'] = $image ? cdnurl($image, true) : $image;
-
- // 分配变量到模板
- $this->view->assign('page', $pageData);
- return $this->view->fetch();
- } else {
- $this->error('未找到页面内容');
- }
- }
- }
|