Create a basic CRUD website with Symfony 4.
2 and some command line helpersalexvoBlockedUnblockFollowFollowingMar 4First download symfony CLI from https://symfony.
com/downloadAfter that you can use the “symfony” command to create projectCreate new symfony project:symfony new –full –version=4.
2 basic_crudGo to the project foldercd basic_crudModify the DATABASE_URL environment variable in the .
env file connect with your database, for example if you use localhost mysql with username root, password empty, database name basic_crud_dbDATABASE_URL=mysql://root:@127.
1:3306/basic_crud_dbYou can create the database directly in your database client interface, or create by Symfony command line:bin/console doctrine:database:createNow let’s make simple article entity (with the “name” property)bin/console make:entityCreate a migration filebin/console make:migrationThe make:migration will create an instruction file contain SQL queryCreate table with information from migration filebin/console doctrine:migrations:migrateNow new table “article” already been created in our basic_crud_db databaseLet’s insert some mock data (via coding)First install fixture which help to insert database record by symfony codecomposer require orm-fixtures –devIt’s time to make a fixturebin/console make:fixturesNow open the fixture file at /src/DataFixtures/ArticleFixture.
php and add some code to create 10 articlesCreate 10 articles named foo1, foo2, …, foo10Run the file to insert records into databasebin/console doctrine:fixtures:loadNow 10 article records already inserted into database, we can check it by the command:bin/console doctrine:query:sql "select * from article"Time to make the view & controllerbin/console make:crudNow run the localhost website:bin/console server:runWe are done.
Let’s enjoy the (pure, ugly) website :))Finish source code can find here(remember to run composer install if you want to run local server from it) https://www.
zip?dl=0.. More details