简介:
Silex是PHP中的微型框架,其特点有:
1/简洁:提供简洁且直观的API
2/可扩展
3/易测试
概括来说,只用一步就可以完成定义控制器并连接路由。
使用:
<?php
// web/index.php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/hello/{name}', function ($name) use ($app) {
return 'Hello '.$app->escape($name);
});
$app->run();
只要include autoload.php 就可以使用该框架
(composer require silex/silex:~2.0)
在代码中定义了 /hello/{name} 路由的GET 请求,当访问该路由时,function将被执行并将值返回给客户端。