이 Skeleton 응용 프로그램을 사용하여 빠르게 설정하고 새로운 Slim Framework 3 응용 프로그램에서 작업을 시작하십시오 (Slim 3.12로 테스트). 이 응용 프로그램은 HTTP 및 명령 줄 요청을 처리합니다. 이 응용 프로그램은 몇몇 서비스 제공 업체와 세션 미들웨어와 함께 배송됩니다. 컨테이너 해상도 및 자동 승리 지원.
서비스 제공 업체를 제거하려면 config/app.php 파일에 댓글을 달고 Composer.json에서 Composer를 업데이트하십시오.
사용 가능한 서비스 제공 업체 :
사용 가능한 미들웨어 :
새 슬림 프레임 워크 응용 프로그램을 설치하려는 디렉토리 에서이 명령을 실행하십시오.
php composer.phar create-project jupitern/slim3-skeleton [my-app-name]
[my-app-name] 새 응용 프로그램의 원하는 디렉토리 이름으로 바꾸십시오. 당신은 원할 것입니다 :
public/ 디렉토리에 가리 킵니다.storage/ 웹에 쓰기가 가능합니다.$ cd [my-app-name]public$ php -S localhost:8080 또는 $ composer serveapp : 응용 프로그램 코드 (모델, 컨트롤러, CLI 명령, 핸들러, 미들웨어, 서비스 제공 업체 및 기타)config : DB, 메일, 경로와 같은 구성 파일 ...lib : Utils, Business Logic 및 Framework 확장과 같은 기타 프로젝트 클래스storage : 로그 파일, 캐시 파일 및 Less, Sass 또는 JavaScript와 같은 원시적 인 통신 자산.public : 공개 디렉토리에는 index.php 파일, 이미지, JavaScript 및 CSS와 같은 자산이 포함되어 있습니다.views :보기 템플릿 파일.vendor : 작곡가 종속성앱 클래스에는 다음과 같은 경로 리졸버 방법이 있습니다.
웹 사이트 및 백엔드 폴더의 두 경로 정의 예 :
use Psr Http Message ServerRequestInterface as Request ;
use Psr Http Message ResponseInterface as Response ;
// simple route example
$ app -> get ( ' /welcome/{name} ' , function ( Request $ request , Response $ response , $ args ) {
$ name = $ request -> getAttribute ( ' name ' );
$ response -> getBody ()-> write ( " Hello, $ name " );
return $ response ;
});
// example route to resolve request to uri '/' to AppHttpSiteWelcome::index
$ app -> any ( ' / ' , function ( $ request , $ response , $ args ) use ( $ app ) {
return $ app -> resolveRoute ([ App Http Welcome::class, " index " ], $ args );
});
// example calling http://localhost:8080/index.php/test/nuno with the route bellow
// injects the :name param value into the method $name parameter
// Other parameters in the method will be searched in the container by classname or automatically resolved
// in this example the resolveRoute method will create a user instance and inject it in the controller method
$ app -> any ( ' /test[/{name}] ' , function ( $ request , $ response , $ args ) use ( $ app ) {
return $ app -> resolveRoute ([ App Http Welcome::class, " method " ], $ args );
});
namespace App Http ;
use Jupitern Slim3 App Http Controller ;
class Welcome extends Controller
{
public function method ( $ name , App Model User $ user )
{
return get_class ( $ user ). " <br/>name = { $ name }" ;
}
}새 명령을 만드는 방법 :
예:
명령 클래스 :
namespace App Console ;
class Test extends Command
{
public function method ( $ a , $ b = ' foobar ' )
{
return
"n Entered console command with params: n" .
" a= { $ a }n" .
" b= { $ b }n" ;
}
}클래스 실행 : 명령 줄에서 메소드 :
// since param "b" is optional you can use one of the following commands
> php cli.php Test method a=foo b=bar
> php cli.php Test method a=foo응용 프로그램 인스턴스를 얻으십시오
$ app = Lib Framework App:: instance ();
// or simpler using a helper function
$ app = app ();디버그 헬퍼 함수를 사용하여 변수, 배열 또는 객체를 디버깅
debug ([ ' a ' , ' b ' , ' c ' ]);
// or debug and exit passing true as second param
debug ([ ' a ' , ' b ' , ' c ' ], true );Laravel Eloquent Service 제공 업체를 사용하여 DB에서 사용자 읽기
$ user = App Model User:: find ( 1 );
echo $ user -> Name ;구성 파일에서 'Mail'이라는 Phpmailer Service 제공자 서비스를 사용하여 이메일 보내기
/* @var $mail PHPMailerPHPMailerPHPMailer */
$ mail = app ()-> resolve ( ' mail ' );
$ mail -> addAddress ( ' [email protected] ' );
$ mail -> Subject = " test " ;
$ mail -> Body = " <b>test body</b> " ;
$ mail -> AltBody = " alt body " ;
$ mail -> send ();구성 파일에서 'fs_local'이라는 Flysystem 서비스 제공 업체가 포함 된 디렉토리 컨텐츠 나열
$ filesystem = app ()-> resolve ( ' fs_local ' );
$ contents = $ filesystem -> listContents ( STORAGE_PATH , true );
var_dump ( $ contents );세션 도우미 수업을 사용하여 세션에서 쓰고 읽습니다
// save user info in session
Jupitern Slim3 Utils Session:: set ( ' user ' , [ ' id ' => ' 1 ' ]);
// get user info from session
$ uservar = Jupitern Slim3 Utils Session:: get ( ' user ' );
var_dump ( $ uservar );Config 파일에서 'redis'라는 Redis 서비스 제공 업체로 캐시에서 쓰기 및 읽기
/** @var JupiternSlim3UtilsRedis $cache */
$ cache = app ()-> resolve ( ' redis ' );
$ cache -> set ( " cacheKey " , " some test value " );
echo $ cache -> get ( " cacheKey " );v3.0
v2.6
v2.5
JUPITERN/SLIM3-SKELETON은 MIT 라이센스에 따라 출시됩니다.