域名和空间都是以前搞下来的,原本是打算搞一个对战小游戏的,因为懒,始终没搞,最近有点颓,早晨常常失眠,撸个站玩玩,就叫 快来玩啊

简略讲一下实现吧:

用的是lumen,整个网站性能很简略,就是介绍一些好玩的物品。

1.数据表 重点就两个: 商品表和配置表

商品表负责保留要介绍的商品信息,简直整站都是从这个表筛选数据进行展现 配置表用来治理一些配置和参数,包含 友情链接、分类、TDK、搜索词等等

  1. 路由 所有get申请定向到同一个控制器

$router->get('{path:.*}', ['uses' => 'PageController@index']);

由该控制器负责 具体页面的散发:

public function index(){     $page = $this -> input('page');  // 中间件依据url解析进去的页面和页面参数    $param = $this -> input('param');     $method = "_".$page;     if(method_exists($this, $method)) { // 间接调用指定页面进行渲染        return call_user_func([$this, $method], $param);     } else {         return redirect() -> route('notfound');     } } // 首页 private function _index($param){     $data = $this -> Data -> get('index'); // 数据service,获取首页数据    return $this -> View -> render('index.html', $data);  // 调用视图渲染进去}
  1. 中间件

定义一个中间件,负责页面的缓存和url解析(其实这步也能够放到控制器),进行伪动态解决

public function handle($request, Closure $next) {    $path = $request -> getPathInfo();    // 缓存判断    if(env('PAGE_CACHE')) {        $cache = env('PAGE_CACHE_PATH').'/'. md5($path);        if(file_exists($cache) && filemtime($cache) > time() - intval(env('PAGE_CACHE_TIME'))) {            return file_get_contents($cache);        }    }    // 缓存生效才会持续    $info = $this -> _dispatch($path); // 一个公有办法,解析出页面名称和参数    $request -> merge($info); // 合并到申请参数    $response = $next($request);    // 缓存更新    if(!empty($cache)) file_put_contents($cache, $response -> getContent());    return $response;}
  1. 其它
  • 应用service层来组织和解决数据
  • 封装了一个简略的dao,用来做crud
  • 用了twig模板引擎,写了几个罕用的filter
  • 页面用了bootstrap, 做了个简略的治理后盾(基于element admin)