Hi there, today I am going to show how to create a basic CRUD with Symfony 4.3.
Please refer to my previous tutorial for Symfony installation Symfony Installation.
Database Configuration:
Modify the environment variable in the .env file connect with your database.
my_symfony_db
Create your database using the following command in your cmd prompt.
bin/console doctrine:database:create
Let's create a simple Entity in the name article
EntityType Field: A special ChoiceType field that's designed to load options from a Doctrine entity.
bin/console make:entity
Now Let's migrate a database
bin/console make:migration
The make:migration will create an instruction file contain SQL query
Let's Create a table with information from the migration file
bin/console doctrine:migrations:migrate
Now new table “article” already been created in our my_symfony_db database
Let's Insert some dummy values through PHP.
First, install fixture which helps to insert database record by Symfony code
Doctrine fixtures are PHP classes where you can create objects and persist them to the database.
composer require orm-fixtures --dev
Make Fixture using the following command
fixture bin/console make:fixtures
Now open the fixture file at /src/DataFixtures/ArticleFixture.php and add some code to create 10 articles
Run the file to insert records into the database
bin/console doctrine:fixtures:load
Let's create crud using following command
bin/console make:crud
Run the command and check your localhost on the browser.
bin/console server:run
Now we are going to add bootstrap style in templates/article/base.html.twig
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
http://127.0.0.1:8000/article/
I Hope you all learned How to Create a basic CRUD with Symfony 4.3.
Happy Coding.
Nice explanation sir..
ReplyDeletePost more tutorials.. it is useful for us
Thank you. We will post more tutorials in php
DeleteSir,
ReplyDeletePlease post symfony 3.4 standard .. user login logout authentication and SESSION tutorials..
Thank you for your request.
DeleteWe will post the tutorial soon, as you requested.