概要
ControllerやCommand,Entityを自動的に作ってくれるコマンドを使えるようにするには
以下のコマンドをプロジェクトのルートディレクトリ上で実行する
terminal
composer require --dev symfony/maker-bundle
makerBundleによって追加されるCommand
- make:auth Creates a Guard authenticator of different flavors
Guard authenticatorを作る(多分新しい権限を作るってことかな?) - make:command Creates a new console command class
新しくコマンドを作る - make:controller Creates a new controller class
コントローラーを作る - make:crud Creates CRUD for Doctrine entity class
クラッドを作る - make:docker:database Adds a database container to your docker-compose.yaml file
データベースをdocker.yamlに入れる - make:entity Creates or updates a Doctrine entity class, and optionally an API Platform resource
エンティティを作る(カラムの名前、データ型、文字数なども設定できました) - make:fixtures Creates a new class to load Doctrine fixtures
よくわからない - make:form Creates a new form class
フォームを作る - make:message Creates a new message and handler
メッセージを作る - make:messenger-middleware Creates a new messenger middleware
メッセンジャーのミドルウェアを作る - make:migration Creates a new migration based on database changes
データベースの変更に基づきマイグレーションを作る - make:registration-form Creates a new registration form system
登録フォームシステムを作る - make:reset-password Create controller, entity, and repositories for use with symfonycasts/reset-password-bundle
パスワードをリセットするためのコントローラー、エンティティ、リポジトリーを作る - make:serializer:encoder Creates a new serializer encoder class
- make:serializer:normalizer Creates a new serializer normalizer class
- make:stimulus-controller Creates a new Stimulus controller
- make:subscriber Creates a new event subscriber class
- make:test [make:unit-test|make:functional-test] Creates a new test class
テストを作る - make:twig-component Creates a twig (or live) component
twigの部品を作る - make:twig-extension Creates a new Twig extension with its runtime class
twigの拡張を作る - make:user Creates a new security user class
セキュアなユーザークラスを作る - make:validator Creates a new validator and constraint class
バリデーターを作る - make:voter Creates a new security voter class
よくわからないやつも何個かありますが、結構使えそうな印象
使用例
entityの作成
bin/console make:entity Tweet
New property name (press <return> to stop adding fields):
> post
Field type (enter ? to see all types) [string]:
>
Field length [255]:
>
Can this field be null in the database (nullable) (yes/no) [no]:
>
updated: src/Entity/Tweet.php
Add another property? Enter the property name (or press <return> to stop adding fields):
>
migrationファイルを作成し、データベーススキーマを更新
bin/console make:migration
bin/console doctrine:migrations:migrate
CRUD作成
php bin/console make:crud
The class name of the entity to create CRUD (e.g. VictoriousChef):
> Tweet
Choose a name for your controller class (e.g. UserController) [UserController]:
>
Do you want to generate tests for the controller?. [Experimental] (yes/no) [no]:
>
最後に
ページを実際に見てみると簡易的なCRUDが実装されていて、データベースとの連携もできていたので、
railsみたいにさくっと実装ができて、とても楽しかったです。
改修案件などはこのコマンド使いにくいかもしれませんが、新規案件などで最初スピーディーにプロジェクト作りたい時は
かなり時間短縮になると思います。
参考にしたサイト=>https://tech.quartetcom.co.jp/