combustor 제공된 데이터베이스 테이블을 기반으로 컨트롤러, 모델 및 뷰를 생성하는 Codeigniter 3용 유틸리티 패키지입니다. 데이터베이스 테이블에서 열을 가져오고 코드 생성의 기초로 설명 패키지를 사용합니다.
Codeigniter 3
프레임워크의 구조를 기반으로 코드를 생성합니다.combustor
알아서 처리합니다. 먼저 최신 Codeigniter 3 프로젝트의 내용을 추출하세요.
$ wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.13.zip
$ unzip 3.1.13.zip -d ciacme
그런 다음 프로젝트의 데이터베이스 연결 설정을 구성합니다.
$ cd ciacme
$ nano application/config/database.php
// ciacme/application/config/database.php
// ...
$ db [ ' default ' ] = array (
' dsn ' => '' ,
' hostname ' => ' localhost ' ,
' username ' => '' ,
' password ' => '' ,
' database ' => '' ,
' dbdriver ' => ' mysqli ' ,
// ...
);
다음은 Composer를 통해 combustor
설치를 진행하는 것입니다.
$ composer require rougin/ combustor --dev
// ciacme/composer.json
{
// ...
"require-dev" :
{
"mikey179/vfsstream" : " 1.6.* " ,
"phpunit/phpunit" : " 4.* || 5.* || 9.* " ,
"rougin/ combustor " : " ~1.0 "
}
}
마지막으로 Wildfire
또는 Doctrine
과 같은 ORM 래퍼를 설치합니다.
$ vendor/bin/ combustor install:wildfire
$ vendor/bin/ combustor install:doctrine
메모
install:wildfire
명령을 사용하면 Wildfire 패키지가 설치되고 install:doctrine
Credo 패키지가 설치됩니다.
명령을 실행하기 전에 코드 구조가 생성된 후 수정을 최소화하기 위해 데이터베이스 테이블이 올바르게 정의되었는지 (외래 키, 인덱스, 관계, 정규화) 확인하십시오.
또한, 데이터베이스 내의 다른 테이블과 관계가 없는 데이터베이스 테이블에 대한 모델, 뷰, 컨트롤러 생성을 먼저 진행하시기 바랍니다.
팁
combustor
지정된 데이터베이스 스키마를 기반으로 컨트롤러, 모델 또는 뷰를 생성합니다. 지정된 데이터베이스 스키마에 문제가 있는 경우 combustor
잘못된 코드베이스를 생성합니다.
create:layout
새 머리글 및 바닥글 파일을 만듭니다.
옵션
--bootstrap
- 부트스트랩을 기반으로 스타일을 추가합니다.--force
- 이미 존재하는 파일을 생성합니다.예
$ vendor/bin/ combustor create-layout --bootstrap
create:controller
새 HTTP 컨트롤러를 만듭니다.
인수
table
- 데이터베이스 테이블의 이름옵션
--doctrine
- Doctrine 기반 컨트롤러를 생성합니다.--wildfire
- Wildfire 기반 컨트롤러를 생성합니다.--empty
- 빈 HTTP 컨트롤러를 생성합니다.--force
- 이미 존재하는 파일을 생성합니다. 메모
Wildfire
또는 Doctrine
설치된 경우 지정된 명령(예: --wildfire
)을 실행하기 위한 옵션으로 지정할 필요가 없습니다. 그러나 둘 다 설치된 경우 명령에 --wildfire
또는 --doctrine
옵션이 추가되어야 합니다.
예
$ vendor/bin/ combustor create:controller users --wildfire
create:model
새 모델을 만듭니다.
인수
table
- 데이터베이스 테이블의 이름옵션
--doctrine
- 교리 기반 모델을 생성합니다.--wildfire
- Wildfire 기반 모델을 생성합니다.--empty
- 빈 모델을 생성합니다.--force
- 이미 존재하는 파일을 생성합니다.예
$ vendor/bin/ combustor create:model users --wildfire
create:repository
새 엔터티 저장소를 만듭니다.
인수
table
- 데이터베이스 테이블의 이름옵션
--force
- 이미 존재하는 파일을 생성합니다.예
$ vendor/bin/ combustor create:repository users
메모
이 명령은 Doctrine 구현에만 적용 가능합니다.
create:view
뷰 템플릿을 생성합니다.
인수
table
- 데이터베이스 테이블의 이름옵션
--bootstrap
- Bootstrap을 기반으로 스타일을 추가합니다.--doctrine
- 교리 기반 보기를 생성합니다.--wildfire
- Wildfire 기반 보기를 생성합니다.--force
- 이미 존재하는 파일을 생성합니다.예
$ vendor/bin/ combustor create:view users --bootstrap
create:scaffold
새로운 HTTP 컨트롤러, 모델 및 뷰 템플릿을 만듭니다.
인수
table
- 데이터베이스 테이블의 이름옵션
--bootstrap
- Bootstrap을 기반으로 스타일을 추가합니다.--doctrine
- Doctrine 기반 컨트롤러, 모델 및 뷰를 생성합니다.--wildfire
- Wildfire 기반 컨트롤러, 모델 및 뷰를 생성합니다.--force
- 이미 존재하는 파일을 생성합니다.예
$ vendor/bin/ combustor create:scaffold users --bootstrap --wildfire
메모
--doctrine
이 선택되면 명령은 create:repository
명령도 실행합니다.
install:doctrine
Doctrine 패키지를 설치합니다.
예
$ vendor/bin/ combustor install:doctrine
메모
Doctrine
설치되어 있지 않은 경우 사용할 수 있습니다.core
디렉터리에 Loader.php
를 추가합니다. 해당 파일은 EntityRepository
로 확장된 사용자 정의 저장소를 로드하는 데 사용됩니다.install:wildfire
Wildfire 패키지를 설치합니다.
예
$ vendor/bin/ combustor install:wildfire
메모
프로젝트에 Wildfire
설치되지 않은 경우 이 명령을 사용할 수 있습니다.
remove:doctrine
Doctrine 패키지를 제거합니다.
예
$ vendor/bin/ combustor remove:doctrine
메모
이 명령은 Doctrine
이 프로젝트에 설치된 경우 사용할 수 있습니다.
remove:wildfire
Wildfire 패키지를 제거합니다.
예
$ vendor/bin/ combustor remove:wildfire
메모
이 명령은 프로젝트에 Wildfire
설치된 경우 사용할 수 있습니다.
combustor .yml
사용 combustor
현재 Installation
기반으로 한 구성 후에 즉시 작동합니다. 그러나 combustor .yml
사용하면 새 애플리케이션 경로 지정 및 열 제외와 같은 복잡한 설정에 사용할 수 있습니다.
# combustor .yml
app_path : %%CURRENT_DIRECTORY%%/Sample
excluded_fields :
- created_at
- updated_at
- deleted_at
combustor .yml
생성하려면 initialize
명령을 실행하면 됩니다.
$ vendor/bin/ combustor initialize
[PASS] " combustor .yml " added successfully !
app_path
이 속성은 application
디렉터리를 지정합니다. 정의된 디렉터리에서 config/config.php
파일을 감지할 수 있는 한 모든 디렉터리(예: ciacme/application
, ciacme/config
등)로 업데이트될 수 있습니다.
# combustor .yml
app_path : %%CURRENT_DIRECTORY%%/Sample
# ...
메모
combustor
유효한 Codeigniter 3
프로젝트인 경우 app_path
에 지정된 경로를 확인하려고 시도합니다. 그런 다음 application
디렉토리가 존재하는지 또는 app_path
에 정의된 디렉토리에서 config
디렉토리에 직접 액세스할 수 있는지 또 다른 확인을 수행합니다.
excluded_fields
이 속성에 지정된 필드는 다음 템플릿 생성에서 제외됩니다.
controllers
models
views
(템플릿 create
및 edit
에만 해당) # combustor .yml
# ...
excluded_fields :
- created_at
- updated_at
- deleted_at
메모
타임스탬프는 일반적으로 Wildfire
또는 Doctrine
과 같은 설치된 ORM에 의해 자동으로 채워지므로 처음으로 combustor .yml
생성할 때 기본적으로 추가됩니다.
custom_fields
기본적으로 페이지를 create
하고 edit
위해 combustor
가 생성한 모든 필드는 form_input
도우미를 사용합니다.
<div class="mb- 3 ">
<?= form_label ( ' Email ' , '' , [ ' class ' => ' form-label mb-0 ' ]) ?>
<?= form_input ( ' email ' , set_value ( ' email ' ), ' class="form-control" ' ) ?>
<?= form_error ( ' email ' , ' <div><span class="text-danger small"> ' , ' </span></div> ' ) ?>
</div>
그러나 email
및 boolean
유형과 같은 일부 필드는 다른 양식 도우미를 사용해야 할 수도 있습니다.
<div class="mb- 3 ">
<?= form_label ( ' Email ' , '' , [ ' class ' => ' form-label mb-0 ' ]) ?>
// Still using form_input, but the type is "email" instead
<?= form_input ([ ' type ' => ' email ' , ' name ' => ' email ' , ' value ' => set_value ( ' email ' ), ' class ' => ' form-control ' ]) ?>
<?= form_error ( ' email ' , ' <div><span class="text-danger small"> ' , ' </span></div> ' ) ?>
</div>
<div class="mb- 3 ">
<?= form_label ( ' Admin ' , '' , [ ' class ' => ' form-label mb-0 ' ]) ?>
// Use "form_checkbox" for boolean-based data types
<div>
<?= form_checkbox ( ' admin ' , true , set_value ( ' admin ' ), ' class="form-check-input" ' ) ?>
</div>
<?= form_error ( ' admin ' , ' <div><span class="text-danger small"> ' , ' </span></div> ' ) ?>
</div>
이를 달성하기 위해 combustor
custom_fields
사용하여 지정된 필드 이름이나 데이터 유형을 처리하기 위한 유틸리티를 제공합니다.
# combustor .yml
# ...
custom_fields :
- Rougin combustor TemplateFieldsBooleanField
사용자 정의 필드를 추가할 때 Colfield
클래스로 확장되는 클래스를 생성하십시오.
namespace Acme Fields ;
use Rougin combustor Colfield ;
class EmailField extends Colfield
{
protected $ class = ' form-control ' ;
/**
* If $name is specified, it will check if the current field
* name matches the in this $name field.
*/
protected $ name = ' email ' ;
public function getPlate ()
{
$ field = $ this -> accessor ;
$ class = $ this -> getClass ();
/** @var string */
$ name = $ this -> getName ();
$ html = ' <?= form_input([ ' type ' => ' email ' , ' name ' => '' . $ name . '' , ' value ' => set_value( '' . $ name . '' )]) ?> ' ;
if ( $ this -> edit )
{
$ html = str_replace ( ' set_value( '' . $ name . '' ) ' , ' set_value( '' . $ name . '' , ' . $ field . ' ) ' , $ html );
}
$ html = str_replace ( ' )]) ?> ' , ' ), ' class ' => '' . $ class . '' ]) ?> ' , $ html );
return array ( $ html );
}
}
그런 다음 사용자 정의 필드를 만든 후 클래스 이름을 combustor .yml
에 추가하기만 하면 됩니다.
# combustor .yml
# ...
custom_fields :
- Rougin combustor TemplateFieldsBooleanField
- AcmeFieldsEmailField
최근 변경된 사항에 대한 자세한 내용은 CHANGELOG를 참조하세요.
$ composer test
MIT 라이센스(MIT). 자세한 내용은 라이센스를 참조하세요.