Пример #1
0
/**
 * Lime blog
 *
 * 此程序只是用于展示 Lime 的功能,并不能用于实际应用
 */
// 加载 Lime 框架
require '../../Lime/Lime.php';
session_start();
date_default_timezone_set('PRC');
// 生成一个 Lime 应用实例
$app = new \Lime\Lime(['resource.path' => __DIR__ . '/usr', 'views.path' => __DIR__ . '/views']);
// 注入服务
$app->service('database', ['className' => '\\Lime\\Pdo', 'arguments' => [['dsn' => 'mysql:host=127.0.0.1;dbname=blog', 'username' => 'root', 'password' => '123456', 'charset' => 'utf8', 'prefix' => 'demo_']]]);
// 中间件
$app->middleware('notFoundHandler', function ($e) {
    return view('404.php', ['exception' => $e]);
});
// 定义请求路由:
$app->get('/', function () {
    return view('index.php');
    // view 辅助函数
});
// 资源式路由
$app->get('/about', '\\Controller\\About@index');
$app->get('/login', function () {
    return view('login.php');
})->filter(function () {
    // 路由过滤
    if (!empty($_SESSION['uid'])) {
        response()->redirect(url_base());
        // 跳转