首先在 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>
```