function get_post($url, $fun)
{
    Route::all($url, $fun);
}
<?php

require_once './vendor/autoload.php';
use sunkangchina\phprouter\Route;
header("Content-type: text/html; charset=utf-8");
define('WEB', realpath(__DIR__ . '/../public/'));
define('BASE', realpath(__DIR__ . '/../'));
include __DIR__ . "/../Route.php";
try {
    $view = Route::run();
    if ($view) {
        echo $view;
    }
} catch (Exception $e) {
    var_dump($e->getMessage());
}
示例#3
0
 /**
  *	渲染视图同make
  */
 function render($name, $par = [])
 {
     if (static::$par) {
         $par = $par + static::$par;
     }
     $name = str_replace('.', '/', $name);
     if (substr($name, 0, 1) == '/') {
         $this->view_dir = $this->view_dir;
         $this->theme_dir = $this->theme_dir;
         $name = substr($name, 1);
     }
     $this->__ex($name);
     $m = Route::controller()['module'];
     unset($n2);
     if ($m) {
         if (strpos($name, '/') !== false) {
             $name = substr($name, strpos($name, '/') + 1);
         }
         $n2 = BASE . '/' . static::$modulePath . '/' . $m . '/views/' . $name . '.php';
     }
     $this->block['content'] = $this->find([$this->theme_file, $this->view_file, $n2]);
     if (!static::$keep_dir) {
         static::$keep_dir = $this->block['content'];
     }
     ob_start();
     extract($par, EXTR_OVERWRITE);
     include $this->block['content'];
     if (file_exists($this->block['layout'])) {
         include $this->block['layout'];
     }
     $data = trim(ob_get_contents());
     ob_end_clean();
     if (true === static::$minify) {
         $data = preg_replace(array('/ {2,}/', '/<!--.*?-->|\\t|(?:\\r?\\n[\\t]*)+/s'), array(' ', ''), $data);
     }
     if (static::$cache !== false && static::$cache >= 0) {
         $url = static::cacheHtml();
         file_put_contents($url, $data);
     }
     return $data;
 }