asgard / http
v0.3.1
2016-05-13 11:31 UTC
Requires
- php: >=5.5.9
- asgard/common: ~0.3.0
- asgard/container: ~0.3.0
- asgard/debug: ~0.3.0
- asgard/file: ~0.3.0
- asgard/hook: ~0.3.0
- asgard/templating: ~0.3.0
- doctrine/annotations: ^1.0
Suggests
- asgard/cache: ~0.3.0
This package is not auto-updated.
Last update: 2024-09-20 06:35:50 UTC
README
#HTTP
处理HTTP请求、路由、控制器和响应的库。
##安装 如果您正在处理Asgard项目,您不需要安装此库,因为它已经是标准库的一部分。
composer require asgard/http 0.*
##请求与响应
处理HTTP请求并构建响应。 查看文档。
$request = \Asgard\Http\Request::createFromGlobals();
//...
return (new \Asgard\Http\Response)->setCode(404)->setContent('not found :(');
##控制器
围绕控制器结构化您的代码。 查看文档。
/**
* @Prefix("products")
*/
class ProductController extends \Asgard\Http\Controller {
/**
* @Prefix("index")
*/
public function indexAction(\Asgard\Http\Request $request) {
//...
}
/**
* @Prefix("search")
*/
public function searchAction(\Asgard\Http\Request $request) {
//...
}
}
##工具
该包附带工具。 查看文档。
###HTML
#in the controller or the page view
$html->includeJS('query.js');
$html->includeCSS('style.css');
#in the layout view
$html->printAll();
###Flash
#in the controller
$flash->addSuccess('Hurray!);
#in the view
$flash->showAll();
###浏览器
$browser = new \Asgard\Http\Browser\Browser($httpKernel, $container);
$browser->getSession()->set('admin_id', 123);
$response = $browser->post('admin/news/new', ['title'=>'foo']);
if($response->getCode() !== 200)
echo 'error..';
else
echo $response->getContent();
##命令
###贡献
请将所有问题和拉取请求提交到 asgardphp/asgard 仓库。
许可协议
Asgard框架是开源软件,遵循 MIT 许可协议