Symfony Commands Nedir ?
3 min readJun 27, 2022
Bazı rutin işleri veya belli bir işleri düzenli olarak yaptırmak için komutlar kullanılır. Symfony’deki bazı sık kullanacağımız bazı komutları göstereceğim.
Tüm commands görmek için
php bin/console
Model ve Repository oluşturur.
php bin/console make:entity Example
created: src/Entity/Example.php
created: src/Repository/ExampleRepository.php
Controller oluştur ve index twig oluşturur.
php bin/console make:controller ExampleController
created: src/Controller/ExampleController.php
created: templates/example/index.html.twig
Fixtures, seeders ile aynı işlevdir. Dummy Data veya gerekli veritabanı kayıtları için kullanılır.
php bin/console make:fixtures ExampleFixtures
created: src/DataFixtures/TestFixtures.php
Varsayılan olarak veritabanını tablolarını tümünü siler ve fixtures çalıştırır.
php bin/console doctrine:fixtures:load
PHP tarafında form oluşturmak için kullanılır.
php bin/console make:form ExampleType
The name of Entity or fully qualified model class name that the new form will be bound to (empty for none):
> Examplecreated: src/Form/ExampleType.php
Otomatik CRUD oluşturma
php bin/console make:crud Task
/var/www/html # php bin/console make:crud TaskChoose a name for your controller class (e.g. TaskController) [TaskController]:
> TaskControllerDo you want to generate tests for the controller?. [Experimental] (yes/no) [no]:
> nocreated: src/Controller/TaskController.php
created: src/Form/TaskType.php
created: templates/task/_delete_form.html.twig
created: templates/task/_form.html.twig
created: templates/task/edit.html.twig
created: templates/task/index.html.twig
created: templates/task/new.html.twig
created: templates/task/show.html.twig
Migration oluşturma:
- Modeller oluşturulduktan sonra php bin/console make:migration çalıştırarak otomatik modellere göre migration dosyasını SQL kodlarıyla oluşturulur.
- Eğer önceden oluşturulan modelde değişiklik yapıldıysa, yapılan değişiklikleri de algılar.
- Oluşturulan migrations dosyalarını çalıştırmada önceden çalışmış olan migrations dosyaları çalışmaz. Başarıyla çalıştırılmış olan migrations dosyalarının bilgileri doctrine_migration_versions tablosunda tutulur.
- Oluşturulan migration dosyalarını çalıştırmak için bu kodu çalıştırın
php bin/console doctrine:migrations:migrate
Schema olarak migration oluşturma
Boş bir migration dosyası oluşturabiliriz.
php bin/console doctrine:migrations:generate
Model’de relation otomatik oluşturma
php bin/console make:entityHangi model ?
Class name of the entity to create or update (e.g. FiercePizza):
> UserYour entity already exists! So let's add some new fields!New property name (press <return> to stop adding fields):
//Hangi değişkenle erişim sağlansın
> tasksField type (enter ? to see all types) [string]:
//Relation yapmak istiyoruz
> relationWhat class should this entity be related to?:
//Hangi modele relation yapacaksınız ?
> TaskWhat type of relationship is this?
//User dan -> Task'a relation hangi tipteyapmak istiyorsunuz ?
------------ ----------------------------------------------------------------
Type Description
------------ ----------------------------------------------------------------
ManyToOne Each User relates to (has) one Task.
Each Task can relate to (can have) many User objectsOneToMany Each User can relate to (can have) many Task objects.
Each Task relates to (has) one UserManyToMany Each User can relate to (can have) many Task objects.
Each Task can also relate to (can also have) many User objectsOneToOne Each User relates to (has) exactly one Task.
Each Task also relates to (has) exactly one User.
------------ ----------------------------------------------------------------Relation type? [ManyToOne, OneToMany, ManyToMany, OneToOne]:
> OneToManyA new property will also be added to the Task class so that you can access and set the related User object from it.New field name inside Task [user]: // Task'dan User bağlanması için hangi değişkenle erişmesini istiyorsunuz ?
> userIs the Task.user property allowed to be null (nullable)? (yes/no) [yes]: // İlişki sırasında bulanamazsa null olabilir mi ?
> noDo you want to activate orphanRemoval on your relationship? //User'ın bilgisiyle Task ekleme ve silmeyi fonksiyonlarını ekleyelim mi?
A Task is "orphaned" when it is removed from its related User.
e.g. $user->removeTask($task)NOTE: If a Task may *change* from one User to another, answer "no".Do you want to automatically delete orphaned App\Entity\Task objects (orphanRemoval)? (yes/no) [no]:
> yes
//Bağlantılı olan orphaned nesnelerini otomatik olarak silmek ister misiniz ?updated: src/Entity/User.php
updated: src/Entity/Task.php