cms文章搜索功能
首先在 cms 控制器中创建 控制器文件 Search.php 如下
<?php namespace app\index\controller; use app\index\service\BaseService; class Search extends Base { //搜索 public function index(){ $keyword = $this->request->param('keyword','','strval'); if(empty($keyword)) $this->error('关键词不能为空'); $this->view->assign('where','title like "%'.$keyword.'%" and status = 1'); $this->view->assign('media', baseService::getMedia()); //网站关键词描述信息 $this->view->assign('pid',0); $this->view->assign('class_name','搜索结果'); $this->view->assign('position','当前位置:搜索结果'); $default_themes = config('xhadmin.default_themes') ? config('xhadmin.default_themes') : 'index'; return $this->display($default_themes.'/search'); } }
模板文件 调用搜索内容 如下
<ul> {page table="content" num="5" sqlstr="$where"} <tr><td width='90%' class='fw_t'>·<a href="{:url('index/View/index',['content_id'=>$page['content_id']])}">{$page.title}</a></td><td width='10%' class='fw_s'>[{$page.create_time|date="Y-m-d"}]</td></tr> {/page} </ul>