你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
anuxs
赞同来自: 豁达于心
<form action = '{{ action('faq@index') }}' method="get"> <p>查询关键字: <input type="text" name="kword"/> <input type="submit" value="查询"/></p> </form>
class faq extends Controller { /** * Display a listing of the resource. * * @return Response */ public $kwords ='-'; public function index() { $kwords = Input::get('kword', ''); //$kwords = "印花税"; //用remember做缓存 // $myResult = Cache::remember($kwords, 360, function() use($kwords){ // $kword = $kwords; // $cou = \App\Faq::whereRaw('contents like ? ',[$kword])->count(); // $faqs =\App\Faq::whereRaw('contents like ? ', [$kword])->get(); // return [$kword => ['cou' =>$cou,'faqs'=>$faqs]]; // }); //用has做缓存判断 $microtimes = microtime(true); $msg=''; if (Cache::has($kwords)) { $myResult = Cache::get($kwords); $msg= '有缓存。本次查询耗时:'. (microtime(TRUE) - $microtimes) .'秒'; } else { $whereStr = "contents like '%".$kwords."%'"; $cou = \App\Faq::whereRaw($whereStr)->count(); $faqs = \App\Faq::whereRaw($whereStr)->get(); Cache::add($kwords, ['cou' => $cou, 'faqs' => $faqs], 360); $myResult = Cache::get($kwords); $msg='无缓存。本次查询耗时:'. (microtime(TRUE) - $microtimes) .'秒'; } //var_dump($myResult); return view('faq', ['faqs' => $myResult['faqs'], 'cou' => $myResult['cou'], 'kword' => $kwords,'msg'=>$msg]); }
要回复问题请先登录或注册
1 个回复
anuxs
赞同来自: 豁达于心
controller里面的代码: