Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

lime

> 编程语言
Open source

micro php web framework

199 stars0 likes0 views
WebsiteGitHub

About

micro php web framework

Lime

Lime is a micro web framework for quickly creating web applications in PHP with minimal effort.

php
$app = new Lime\App();

$app->bind("/", function() {
    return "Hello World!";
});

$app->run();

Just include one file (~ 35KB) and you're ready to go.

Routes

In Lime, a route is an HTTP method paired with a URL-matching pattern. Each route is associated with a block:

php
$app->get("/", function() {
    return "This was a GET request...";
});

$app->post("/", function() {
    return "This was a POST request...";
});

$app->bind("/", function() {
    return "This was a GET or POST request...";
});

Routes are matched in the order they are defined. The first route that matches the request is invoked.

Route patterns may include named parameters, accessible via the params hash:

php
$app->get("/posts/:id/:name", function($params) {
    return $params["id"].'-'.$params["name"];
});

$app->post("/misc/*", function($params) {
    return $params[":splat"];
});

$app->bind("#/pages/(about|contact)#", function($params) {
    return implode("\n", $params[":captures"]);
});

Conditions

Routes may include a variety of matching conditions, such as the user agent:

php
$app->get("/foo", function() {
    // GET request...
}, strpos($_SERVER['HTTP_USER_AGENT'], "Safari")!==false);

Create Urls

php
$route = $app->routeUrl('/my/route');
$url   = $app->baseUrl('/assets/script.js');

Templates

In general you can utilize any template engine you want. Lime provides a simple template engine:

php
$app->get("/", function() {

        $data = array(
            "name"  => 'Frank',
            "title" => 'Template demo'
        );

        return $this->render("views/view.php with views/layout.php", $data);
});

views/view.php:

php

    Hello .

views/layout.php:

php

        
        

        routeUrl('/')?>">Home
        

        

You like OO style?

Just bind a class:

…

Registry

Store any values by setting a key to the $app object.

php
$app["config.mykey"] = array('test' => 123);

Path access helper with /

php
$value = $app["config.mykey/test"]; // will return 123

Paths

Register paths for quicker access

php
$app->path('views', __DIR__.'/views');

$view = $app->path('views:detail.php');
$view = $app->render('views:detail.php');

Gets url to file

php
$url  = $app->pathToUrl('folder/file.php');
$url  = $app->pathToUrl('view:file.php');

Dependency injection

php
$app->service("db", function(){

    // object will be lazy created after accessing $app['db']
    $obj = new PDO(...);

    return $obj;

});

$app["db"]->query(...);

Events

php

// register callback
$app->on("customevent", function(){
    // code to execute on event
}, $priority = 0);

// trigger custom events
$app->trigger("customevent", $params=array());

You can utilize three system events: before, after and shutdown

php
// render custom error pages

$app->on("after", function() {

    switch($this->response->status){
        case "404":
            $this->response->body = $this->render("views/404.php");
            break;
        case "500":
            $this->response->body = $this->render("views/500.php");
            break;
    }
});

Helpers

You can extend Lime by using your custom helpers:

php
class MyHelperClass extends Lime\Helper {

    public function test(){
        echo "Hello!";
    }
}

$app->helpers["myhelper"] = 'MyHelperClass';

$app("myhelper")->test();

Build in helpers

Session

php
$app("session")->init($sessionname=null);
$app("session")->write($key, $value);
$app("session")->read($key, $default=null);
$app("session")->delete($key);
$app("session")->destroy();

Cache

php
$app("cache")->setCachePath($path);
$app("cache")->write($key, $value, $duration = -1);
$app("cache")->read($key, $default=null);
$app("cache")->delete($key);
$app("cache")->clear();

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言