码迷,mamicode.com
首页 > 其他好文 > 详细

slim

时间:2015-12-01 12:31:36      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

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

安装使用Composer

composer require slim/slim

vendor\slim\slim\index.php

<?php
require ‘Slim/Slim.php‘;
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
// 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"

获取某项配置

slim

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!