php express
Version 2.0.0
Express.js에서 영감을 얻은 PHP 마이크로 프레임 워크
| 짓다 | Github 페이지 | 안정적인 | 특허 |
|---|---|---|---|
ext-json )Composer가 시스템에 아직 설치되지 않은 경우이 명령 줄을 사용하여 계속 설치할 수 있습니다.
$ curl -sS https://getcomposer.org/installer | php
그런 다음 프로젝트의 루트에있는 composer.json 파일에 대한 다음 항목을 추가하십시오.
{
"require" : {
"riverside/php-express" : " ^2.0 "
}
}마지막으로 Composer를 사용하여 PHP-Express 및 그 종속성을 설치하십시오.
$ php composer.phar install
<?php
$ app = new Riverside Express Application ();
$ app -> get ( ' / ' , function ( $ req , $ res ) {
$ res -> send ( ' hello world ' );
}); <?php
// GET method route
$ app -> get ( ' / ' , function ( $ req , $ res ) {
$ res -> send ( ' GET request to the homepage ' );
});
// POST method route
$ app -> post ( ' / ' , function ( $ req , $ res ) {
$ res -> send ( ' POST request to the homepage ' );
}); <?php
$ app -> get ( ' / ' , function ( $ req , $ res ) {
$ res -> send ( ' root ' );
});
$ app -> get ( ' about ' , function ( $ req , $ res ) {
$ res -> send ( ' about ' );
});
$ app -> get ( ' random.text ' , function ( $ req , $ res ) {
$ res -> send ( ' random.text ' );
});| 방법 | 설명 |
|---|---|
| $ res-> end () | 응답 과정을 종료하십시오. |
| $ res-> json () | JSON 응답을 보내십시오. |
| $ res-> redirect () | 요청을 리디렉션합니다. |
| $ res-> render () | 보기 템플릿을 렌더링하십시오. |
| $ res-> send () | 다양한 유형의 응답을 보내십시오. |
| $ res-> sendstatus () | 응답 상태 코드를 설정하고 문자열 표현을 응답 본문으로 보냅니다. |
<?php
$ app -> route ( ' /book ' )
-> get ( function ( $ req , $ res ) {
$ res -> send ( ' Get a random book ' );
})
-> post ( function ( $ req , $ res ) {
$ res -> send ( ' Add a book ' );
})
-> put ( function ( $ req , $ res ) {
$ res -> send ( ' Update the book ' );
}); <?php
$ router = new Riverside Express Router ( $ app );
$ router -> param ( ' uuid ' , ' [a-fd]{8}-[a-fd]{4}-[a-fd]{4}-[a-fd]{4}-[a-fd]{12} ' );
$ router -> get ( ' / ' , function ( $ req , $ res ) {
$ res -> send ( ' Birds home page ' );
});
$ router -> get ( ' about ' , function ( $ req , $ res ) {
$ res -> send ( ' About birds ' );
});
$ router -> get ( ' ticket/:uuid/ ' , function ( $ req , $ res ) {
echo $ req -> params [ ' uuid ' ];
});
$ router -> run (); $ app -> use ( function ( $ req , $ res ) {
$ res -> header ( ' X-Frame-Options ' , ' DENY ' );
$ res -> header ( ' X-Powered-By ' , false );
});
$ app -> use ( ' /cors ' , function ( $ req , $ res ) {
$ res -> header ( ' Access-Control-Allow-Origin ' , ' * ' );
});