slim

Slim 是一个非常优雅的 PHP 微框架,非常适合做API,支持多种http请求方式,比如get,post,delete,put等

安装使用Composer

composer require slim/slim

vendorslimslimindex.php

<?php
require 'Slim/Slim.php';
SlimSlim::registerAutoloader();
$app = new SlimSlim();
// GET route
$app->get(
    '/',
    function () {
        
        echo "Hello Slim";
    }
);
// POST route
$app->post(
    '/post',
    function () {
        echo 'This is a POST route';
    }
);
// PUT route
$app->put(
    '/put',
    function () {
        echo 'This is a PUT route';
    }
);
// PATCH route
$app->patch('/patch', function () {
    echo 'This is a PATCH route';
});

// DELETE route
$app->delete(
    '/delete',
    function () {
        echo 'This is a DELETE route';
    }
);
$app->run();

可以使用火狐浏览器中的HTTPRequest工具测试

 Slim 框架提供了两种方式对其进行配置。

一种是在生成实例的时候进行参数设置,另一种则是在生成实例之后,设置参数可以在生成实例的时候以数组的形式传递给 Slim 的构造函数

定义设置

$app = new Slim(array(
    'debug' => true
));

实例生成之后

$app->config(array(
     'debug' => true,
     'templates.path' => ' ../templates'
));
$settingValue = $app->config('templates.path'); // 返回 "../templates"

获取某项配置

原文地址:https://www.cnblogs.com/baby123/p/5009519.html