Mardira Framework는 웹 응용 프로그램 및 API를 구축하기위한 PHP 프레임 워크 모델 컨트롤러입니다. 단순하고 빠르도록 설계되었습니다.
mardira-framework
├── App
│ ├── Controllers
│ │ ├── AuthController.php
│ ├── Core
│ │ ├── Commands
│ ├── Database
│ │ ├── Migrations
│ │ │ ├── 2023_01_31_xxxxxx_create_table_users.php
│ │ │ ├── 2023_01_31_xxxxxx_create_table_roles.php
│ │ ├── Seeders
│ │ │ ├── GlobalSeeder.php
│ ├── Helpers
│ ├── Middleware
│ ├── Models
│ ├── Packages
│ ├── Routes
│ │ ├── Api.php작곡가를 사용하여 새 프로젝트를 만들 수 있습니다
composer create-project mardira/mardira-framework < your_project_name >또는이 프로젝트를 복제 할 수 있습니다
git clone https://github.com/Bootcamp-STMIK-Mardira-Indonesia/mardira-framework.git그런 다음 작곡가를 사용하여 종속성을 설치하십시오
composer install또는
composer updatephp mardira serve또는
php mardira serve --port= < your_port >명령을 사용하여 .env 파일을 만들 수 있습니다
php mardira make:envphp mardira make:controller ControllerNamephp mardira make:model ModelNamephp mardira make:route route_name --controller=ControllerNamephp mardira make:migration create_table_table_name데이터베이스가 존재하지 않으면 .env에서 데이터베이스를 자동으로 생성합니다.
php mardira migratephp mardira migrate:refreshphp mardira migrate:refresh --seedphp mardira make:seeder SeederNamephp mardira db:seedphp mardira db:seed --class=SeederNamephp mardira make:authphp mardira make:auth --refreshphp mardira update컨트롤러 작성
php mardira make:controller ControllerName, 여기 예제 컨트롤러가 있습니다.
<?php
namespace App Controllers ;
use App Core Controller ;
class HomeController extends Controller
{
public function index ()
{
$ this -> response ( 200 ,[
' message ' => ' Hello World '
]);
}
}컨트롤러를 사용하려면
App/Routes/Api.php에 경로를 추가 할 수 있습니다
<?php
use App Core Route ;
use App Controllers HomeController ;
Route:: get ( ' /home ' , [HomeController::class, ' index ' ]);컨트롤러에서 응답을 사용할 수 있습니다
$ this -> response ( 200 ,[
' message ' => ' Hello World '
]);JSON이 기대합니다
{
"message" : " Hello World "
}또 다른 응답 예 409
$ this -> response -> json ( 409 ,[
' message ' => ' Conflict '
]);모델
php mardira make:model ModelName
<?php
namespace App Models ;
use App Core Model ;
class User extends Model
{
protected $ table = ' users ' ;
protected $ primaryKey = ' id ' ;
}모델을 사용하려면
App/Controllers/ControllerName.php에서 모델을 추가 할 수 있습니다
<?php
namespace App Controllers ;
use App Core Controller ;
use App Models User ;
class HomeController extends Controller
{
public function index ()
{
$ user = User:: all ();
$ this -> response ( 200 ,[
' message ' => ' Hello World ' ,
' data ' => $ user
]);
}
}마이그레이션 생성
php mardira make:migration create_table_table_name, 여기 예제 마이그레이션이 있습니다.
<?php
namespace App Database Migrations ;
use App Core Migration ;
return new class extends Migration
{
public function up ()
{
$ this -> schema -> create ( ' users ' , function ( $ table ) {
$ table -> increment ( ' id ' );
$ table -> string ( ' name ' , 50 );
$ table -> string ( ' email ' , 50 )-> unique ();
$ table -> string ( ' password ' , 64 );
$ table -> timestamps ();
});
}
public function down ()
{
$ this -> schema -> dropIfExists ( ' users ' );
}
}씨앗 생성
php mardira make:seeder SeederName, 여기 예시 시러가 있습니다.
<?php
namespace App Database Seeders ;
use App Core Seeder ;
use App Core QueryBuilder as DB ;
class UserSeeder extends Seeder
{
public function run ()
{
$ data = [
[
' name ' => ' Administrator ' ,
' username ' => ' admin ' ,
' email ' => ' [email protected] ' ,
' password ' => password_hash ( ' password ' , PASSWORD_DEFAULT ),
' role_id ' => 1 ,
],
[
' name ' => ' User ' ,
' username ' => ' user ' ,
' email ' => ' [email protected] ' ,
' password ' => password_hash ( ' password ' , PASSWORD_DEFAULT ),
' role_id ' => 2 ,
]
];
DB :: table ( ' users ' )-> insert ( $ data );
}
}미들웨어 생성
php mardira make:middleware MiddlewareName, 여기 예제 미들웨어가 있습니다.
<?php
namespace App Middleware ;
use App Core Middleware ;
use App Core Auth ;
class AuthMiddleware extends Middleware
{
public function handle ()
{
if (Auth:: check ()) {
return $ next ();
}
return $ this -> response ( 401 , [ ' message ' => ' Unauthorized ' ]);
}
}미들웨어를 사용하려면 경로에 미들웨어를 추가 할 수 있습니다
Router:: get ( ' /schedules ' , [ScheduleController::class, ' index ' ], [AuthMiddleware::class]);
App/Routes/Api.php에 경로를 추가 할 수 있습니다
<?php
use App Core Route ;
Router:: get ( ' /home ' , [HomeController::class, ' index ' ]);
App/Routes/Api.php에서 Route Group을 추가 할 수 있습니다
<?php
use App Core Route ;
Router:: controller (ProductController::class)-> group ( function () {
Router:: post ( ' /products/store ' , ' store ' );
}); use App Core QueryBuilder as DB ; DB :: table ( ' users ' )-> select ( ' name ' , ' email ' )-> get (); // equal
DB :: table ( ' users ' )-> where ( ' id ' , 1 )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' > ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' < ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' >= ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' <= ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' != ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' <> ' )-> get ();
// like
DB :: table ( ' users ' )-> where ( ' name ' , ' admin ' , ' like ' )-> get ();
DB :: table ( ' users ' )-> where ( ' name ' , ' admin ' , ' not like ' )-> get (); DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' > ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' < ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' >= ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' <= ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' != ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' <> ' )-> get (); DB :: table ( ' users ' )-> whereIn ( ' id ' , [ 1 , 2 , 3 ])-> get ();
DB :: table ( ' users ' )-> whereNotIn ( ' id ' , [ 1 , 2 , 3 ])-> get (); DB :: table ( ' users ' )-> whereNotIn ( ' id ' , [ 1 , 2 , 3 ])-> get (); DB :: table ( ' users ' )-> whereNull ( ' id ' )-> get (); DB :: table ( ' users ' )-> whereNotNull ( ' id ' )-> get (); DB :: table ( ' users ' )-> orderBy ( ' id ' , ' desc ' )-> get ();
DB :: table ( ' users ' )-> orderBy ( ' id ' , ' asc ' )-> get (); DB :: table ( ' users ' )
-> join ( ' roles ' , ' users.role_id ' , ' = ' , ' roles.id ' )
-> select ( ' users.* ' , ' roles.name as role_name ' )
-> get (); DB :: table ( ' users ' )
-> groupBy ( ' role_id ' )
-> get (); DB :: table ( ' users ' )-> insert ([
' name ' => ' user ' ,
' email ' => ' [email protected] ' ,
' password ' => password_hash ( ' password ' , PASSWORD_DEFAULT ),
]); DB :: table ( ' users ' )-> where ( ' id ' , 1 )-> update ([
' name ' => ' user ' ,
' email ' => ' [email protected] ' ,
]); DB :: table ( ' users ' )-> where ( ' id ' , 1 )-> delete (); DB :: table ( ' users ' )-> count ();다음 장소 중 하나에서 나에게 연락하십시오!
demostmikmi.com 웹 사이트