Search.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 海豚PHP框架 [ DolphinPHP ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://dolphinphp.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
  10. // +----------------------------------------------------------------------
  11. namespace app\cms\home;
  12. use think\Db;
  13. /**
  14. * 前台搜索控制器
  15. * @package app\cms\admin
  16. */
  17. class Search extends Common
  18. {
  19. /**
  20. * 搜索列表
  21. * @param string $keyword 关键词
  22. * @author 蔡伟明 <314013107@qq.com>
  23. * @return mixed
  24. */
  25. public function index($keyword = '')
  26. {
  27. if ($keyword == '') $this->error('请输入关键字');
  28. $map = [
  29. 'cms_document.trash' => 0,
  30. 'cms_document.status' => 1,
  31. 'cms_document.title' => ['like', "%$keyword%"]
  32. ];
  33. $data_list = Db::view('cms_document', true)
  34. ->view('admin_user', 'username', 'cms_document.uid=admin_user.id', 'left')
  35. ->where($map)
  36. ->order('create_time desc')
  37. ->paginate(config('list_rows'));
  38. $this->assign('keyword', $keyword);
  39. $this->assign('lists', $data_list);
  40. $this->assign('pages', $data_list->render());
  41. return $this->fetch(); // 渲染模板
  42. }
  43. }