SlideShare a Scribd company logo
1 of 9
Add data in Symfony4
Vederea data/index.html.twig
{% extends 'base.html.twig' %}
{% block body %}
<table>
<tr>
<th>id</th>
<th>nume</th>
<th>culoare</th>
<th>marime</th>
<th>pret</th>
</tr>
{% for key in flowers %}
<tr>
<td>{{ key.id }}</td>
<td>{{ key.nume }}</td>
<td>{{ key.culoare }}</td>
<td> {{ key.marime }}</td>
<td>{{ key.pret }}</td>
</tr>
{% endfor %}
</table>
<a href="{{ app.request.baseUrl() }}/data/add">Insert a record</a>
{% endblock %}
Vederea data/add.html.twig
{% extends 'base.html.twig' %}
{% block body %}
<div class="container">
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
</div>
{% endblock %}
Controller-ul DataController
<?php
namespace AppController;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentHttpFoundationRequest;
use AppEntityFlower;
use SymfonyComponentFormExtensionCoreTypeTextType;
use SymfonyComponentFormExtensionCoreTypeNumberType;
use SymfonyComponentFormExtensionCoreTypeSubmitType;
class DataController extends Controller
{
/**
* @Route("/data", name="data")
*/
public function index(Request $request)
{
$flower = $this->getDoctrine()-
>getRepository(Flower::class)->findAll();
return $this->render('data/index.html.twig',
array('flowers'=>$flower));
}
/**
* @Route("/data/add", name="add")
*/
public function addAction(Request $request)
{
$flower=new Flower;
$form=$this->createFormBuilder($flower)
->setAction($this->generateUrl('save'))//se utilizeaza numele
controlului adnotat!!!
->setMethod('POST')
->add('nume',TextType::class)
->add('culoare',TextType::class)
->add('marime',TextType::class)
->add('pret',NumberType::class)
->add('submit', SubmitType::class)
->getForm();
$form->handleRequest($request);
return $this->render('data/add.html.twig',array('form'=>$form-
>createView()));
}
/**
* @Route("/data/save", name="save")
*/
public function saveAction(Request $request)
{
$flower = new Flower;
$var = $request->request->all();
$nume = $var['form']['nume'];
$culoare = $var['form']['culoare'];
$marime = $var['form']['marime'];
$pret = $var['form']['pret'];
//se apeleaza functiile set din Flower.php
$flower->setNume($nume);
$flower->setCuloare($culoare);
$flower->setMarime($marime);
$flower->setPret($pret);
$em = $this->getDoctrine()->getManager();
//informeaza Doctrine ca urmeaza sa salvam datele
$em->persist($flower);
//executa interogarea
$em->flush();
return $this->redirectToRoute('data');
}
}
• Forma generata va fi:

More Related Content

What's hot

Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)Linux User's Group
 
FYBSC IT Web Programming Unit II Html 5 Tables, Forms and Media
FYBSC IT Web Programming Unit II  Html 5 Tables, Forms and MediaFYBSC IT Web Programming Unit II  Html 5 Tables, Forms and Media
FYBSC IT Web Programming Unit II Html 5 Tables, Forms and MediaArti Parab Academics
 
Html table tags
Html table tagsHtml table tags
Html table tagseShikshak
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTMLMarlon Jamera
 
Html table
Html tableHtml table
Html tableJayjZens
 
IDCC 2011, What Your Tweets Tell Us About You, Appendix A
IDCC 2011, What Your Tweets Tell Us About You, Appendix AIDCC 2011, What Your Tweets Tell Us About You, Appendix A
IDCC 2011, What Your Tweets Tell Us About You, Appendix Auclagovinfolibrarian
 
FYBSC IT Web Programming Unit I HTML 5 & andcss
FYBSC IT Web Programming Unit I HTML 5 & andcssFYBSC IT Web Programming Unit I HTML 5 & andcss
FYBSC IT Web Programming Unit I HTML 5 & andcssArti Parab Academics
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTMLDoncho Minkov
 
Web forms and html lecture Number 3
Web forms and html lecture Number 3Web forms and html lecture Number 3
Web forms and html lecture Number 3Mudasir Syed
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)club23
 

What's hot (20)

html-table
html-tablehtml-table
html-table
 
Html basics
Html basicsHtml basics
Html basics
 
Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)
 
HTML Table Tags
HTML Table TagsHTML Table Tags
HTML Table Tags
 
HTML Tutorials
HTML TutorialsHTML Tutorials
HTML Tutorials
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
 
FYBSC IT Web Programming Unit II Html 5 Tables, Forms and Media
FYBSC IT Web Programming Unit II  Html 5 Tables, Forms and MediaFYBSC IT Web Programming Unit II  Html 5 Tables, Forms and Media
FYBSC IT Web Programming Unit II Html 5 Tables, Forms and Media
 
Html table tags
Html table tagsHtml table tags
Html table tags
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTML
 
HTML 4.0
HTML 4.0HTML 4.0
HTML 4.0
 
Basic tags
Basic tagsBasic tags
Basic tags
 
Basic tags
Basic tagsBasic tags
Basic tags
 
Html table
Html tableHtml table
Html table
 
Tags list of html and css
Tags list of html and cssTags list of html and css
Tags list of html and css
 
IDCC 2011, What Your Tweets Tell Us About You, Appendix A
IDCC 2011, What Your Tweets Tell Us About You, Appendix AIDCC 2011, What Your Tweets Tell Us About You, Appendix A
IDCC 2011, What Your Tweets Tell Us About You, Appendix A
 
FYBSC IT Web Programming Unit I HTML 5 & andcss
FYBSC IT Web Programming Unit I HTML 5 & andcssFYBSC IT Web Programming Unit I HTML 5 & andcss
FYBSC IT Web Programming Unit I HTML 5 & andcss
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTML
 
Web forms and html lecture Number 3
Web forms and html lecture Number 3Web forms and html lecture Number 3
Web forms and html lecture Number 3
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
 
html
htmlhtml
html
 

Similar to Add and display data in Symfony 4

Similar to Add and display data in Symfony 4 (20)

17. delete data
17. delete data17. delete data
17. delete data
 
13. view data
13. view data13. view data
13. view data
 
data insert in codeigniter.pptx
data insert in codeigniter.pptxdata insert in codeigniter.pptx
data insert in codeigniter.pptx
 
vue-components.pdf
vue-components.pdfvue-components.pdf
vue-components.pdf
 
Lect# 1 html part ii
Lect# 1 html part iiLect# 1 html part ii
Lect# 1 html part ii
 
Creating web api and consuming part 2
Creating web api and consuming part 2Creating web api and consuming part 2
Creating web api and consuming part 2
 
Lab final
Lab finalLab final
Lab final
 
HTML Tables and Forms
HTML Tables and Forms HTML Tables and Forms
HTML Tables and Forms
 
Database connectivity in PHP
Database connectivity in PHPDatabase connectivity in PHP
Database connectivity in PHP
 
Ôn tập KTTMDT
Ôn tập KTTMDTÔn tập KTTMDT
Ôn tập KTTMDT
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivity
 
9. Php MongoDB cautarea unui document
9. Php MongoDB cautarea unui document9. Php MongoDB cautarea unui document
9. Php MongoDB cautarea unui document
 
6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui document6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui document
 
Creating simple php contact form
Creating simple php contact formCreating simple php contact form
Creating simple php contact form
 
Form & frame
Form & frameForm & frame
Form & frame
 
high
highhigh
high
 
Html
HtmlHtml
Html
 
Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5
 
Bad Form @ Form, Function & Class 2016
Bad Form @ Form, Function & Class 2016Bad Form @ Form, Function & Class 2016
Bad Form @ Form, Function & Class 2016
 

More from Razvan Raducanu, PhD (20)

12. edit record
12. edit record12. edit record
12. edit record
 
11. delete record
11. delete record11. delete record
11. delete record
 
10. view one record
10. view one record10. view one record
10. view one record
 
9. add new record
9. add new record9. add new record
9. add new record
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
7. copy1
7. copy17. copy1
7. copy1
 
6. hello popescu 2
6. hello popescu 26. hello popescu 2
6. hello popescu 2
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
 
4. forme in zend framework 3
4. forme in zend framework 34. forme in zend framework 3
4. forme in zend framework 3
 
3. trimiterea datelor la vederi
3. trimiterea datelor la vederi3. trimiterea datelor la vederi
3. trimiterea datelor la vederi
 
2.routing in zend framework 3
2.routing in zend framework 32.routing in zend framework 3
2.routing in zend framework 3
 
1. zend framework intro
1. zend framework intro1. zend framework intro
1. zend framework intro
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
 
16. edit data
16. edit data16. edit data
16. edit data
 
12.doctrine view data
12.doctrine view data12.doctrine view data
12.doctrine view data
 
11. move in Symfony 4
11. move in Symfony 411. move in Symfony 4
11. move in Symfony 4
 
10. add in Symfony 4
10. add in Symfony 410. add in Symfony 4
10. add in Symfony 4
 
9. lower in Symfony 4
9. lower in Symfony 49. lower in Symfony 4
9. lower in Symfony 4
 
8. radio1 in Symfony 4
8. radio1 in Symfony 48. radio1 in Symfony 4
8. radio1 in Symfony 4
 
7. copy2 in Symfony 4
7. copy2 in Symfony 47. copy2 in Symfony 4
7. copy2 in Symfony 4
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Add and display data in Symfony 4

  • 1. Add data in Symfony4
  • 2. Vederea data/index.html.twig {% extends 'base.html.twig' %} {% block body %} <table> <tr> <th>id</th> <th>nume</th> <th>culoare</th> <th>marime</th> <th>pret</th> </tr> {% for key in flowers %} <tr> <td>{{ key.id }}</td> <td>{{ key.nume }}</td> <td>{{ key.culoare }}</td> <td> {{ key.marime }}</td> <td>{{ key.pret }}</td> </tr> {% endfor %} </table> <a href="{{ app.request.baseUrl() }}/data/add">Insert a record</a> {% endblock %}
  • 3. Vederea data/add.html.twig {% extends 'base.html.twig' %} {% block body %} <div class="container"> {{ form_start(form) }} {{ form_widget(form) }} {{ form_end(form) }} </div> {% endblock %}
  • 4. Controller-ul DataController <?php namespace AppController; use SymfonyComponentRoutingAnnotationRoute; use SymfonyBundleFrameworkBundleControllerController; use SymfonyComponentHttpFoundationRequest; use AppEntityFlower; use SymfonyComponentFormExtensionCoreTypeTextType; use SymfonyComponentFormExtensionCoreTypeNumberType; use SymfonyComponentFormExtensionCoreTypeSubmitType;
  • 5. class DataController extends Controller { /** * @Route("/data", name="data") */ public function index(Request $request) { $flower = $this->getDoctrine()- >getRepository(Flower::class)->findAll(); return $this->render('data/index.html.twig', array('flowers'=>$flower)); }
  • 6. /** * @Route("/data/add", name="add") */ public function addAction(Request $request) { $flower=new Flower; $form=$this->createFormBuilder($flower) ->setAction($this->generateUrl('save'))//se utilizeaza numele controlului adnotat!!! ->setMethod('POST') ->add('nume',TextType::class) ->add('culoare',TextType::class) ->add('marime',TextType::class) ->add('pret',NumberType::class) ->add('submit', SubmitType::class) ->getForm(); $form->handleRequest($request); return $this->render('data/add.html.twig',array('form'=>$form- >createView())); }
  • 7. /** * @Route("/data/save", name="save") */ public function saveAction(Request $request) { $flower = new Flower; $var = $request->request->all(); $nume = $var['form']['nume']; $culoare = $var['form']['culoare']; $marime = $var['form']['marime']; $pret = $var['form']['pret']; //se apeleaza functiile set din Flower.php $flower->setNume($nume); $flower->setCuloare($culoare); $flower->setMarime($marime); $flower->setPret($pret);
  • 8. $em = $this->getDoctrine()->getManager(); //informeaza Doctrine ca urmeaza sa salvam datele $em->persist($flower); //executa interogarea $em->flush(); return $this->redirectToRoute('data'); } }