Home >Backend Development >PHP Tutorial >PHP微框架Dispatch简介_PHP

PHP微框架Dispatch简介_PHP

WBOY
WBOYOriginal
2016-06-01 11:51:161523browse

Dispatch是一个PHP小框架。它并没有给你完整的MVC设置,但你可以定义URL规则和方法,以便更好组织应用程序。这对API、简单的站点或原型来说是完美的。

复制代码 代码如下:
//包含库
include 'dispatch.php';
// 定义你的路由
get('/greet', function () {
//渲染视图
render('greet-form');
});
//post处理
post('/greet', function () {
$name = from($_POST, 'name');
// render a view while passing some locals
render('greet-show', array('name' => $name));
});
// serve your site
dispatch();


你可以匹配特定类型的HTTP请求和路径,渲染视图或做更多事情。如果你合并Dispatch和其他框架,那你就可以拥有一个相当强大并且轻量级的程序!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn