SlideShare uma empresa Scribd logo
1 de 9
Radio1
• composer create-project symfony/website-skeleton symfony6
• cd symfony6
• php bin/console make:controller
>RadioController
• composer php/bin server:start
• http://localhost:8000/copy
Vederea base.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock
%}</title>
{% block stylesheets %}{% endblock %}
</head>
<body bgcolor="aquamarine">
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
</body>
</html>
Vederea radio/index.html.twig
{% extends 'base.html.twig' %}
{% block title %}Copy!{% endblock %}
{% block body %}
{{head|raw}}
{{ form_start(form) }}
{{ form_row(form.radio) }}
{{ form_end(form) }}
{% endblock %}
Vederea radio/output.html.twig
{% extends 'base.html.twig' %}
{% block title %}Copy!{% endblock %}
{% block body %}
{{value|raw}}
{% endblock %}
Controller-ul RadioController
<?php
namespace AppController;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentForm;
use SymfonyComponentFormExtensionCoreTypeTextType;
use SymfonyComponentFormExtensionCoreTypeSubmitType;
use SymfonyComponentFormExtensionCoreTypeRadioType;
use SymfonyComponentFormExtensionCoreTypeChoiceType;
class RadioController extends Controller
{
/**
* @Route("/radio", name="radio")
*/
public function index(Request $request)
{
$data=[];
$form=$this->createFormBuilder()
->setAction($this->generateUrl('output'))//se utilizeaza numele controlului
adnotat!!!
->setMethod('POST')
->add('radio', ChoiceType::class, array(
'choices' => array('Popescu' => 'Popescu', 'Ionescu' => 'Ionescu',
'Georgescu'=>'Georgescu'),
'expanded' => true,
'multiple' => false,
'label'=>false,
))
->add('submit', SubmitType::class)
->getForm();
$form->handleRequest($request);
$data['head']="<h1>Choose:</h1>";
$data['form']=$form->createView();
if($form->isSubmitted()){
switch($form->get('radio')->getData()){
case 'Popescu':
$data['value'] = 'Popescu';
break;
case 'Ionescu';
$data['value'] = 'Ionescu';
break;
case 'Georgescu';
$data['value'] = 'Georgescu';
break;
default:
$data['value'] = 'Vai! vai! vai!';
}
}
return $this->render('radio/index.html.twig', $data);
}
/**
* @Route("/output", name="output")
*/
public function output(Request $request)
{
$var = $request->request->all();
$data['value']="Hello <b>".$var['form']['radio']."</b>!";
return $this->render('radio/output.html.twig', $data);
}
}

Mais conteúdo relacionado

Semelhante a 8. radio1 in Symfony 4

1 Introduction to PHP Overview This lab walks y.docx
1  Introduction to PHP Overview This lab walks y.docx1  Introduction to PHP Overview This lab walks y.docx
1 Introduction to PHP Overview This lab walks y.docx
honey725342
 

Semelhante a 8. radio1 in Symfony 4 (20)

13. view data
13. view data13. view data
13. view data
 
Simple Markdown with Ecto and Protocols
Simple Markdown with Ecto and ProtocolsSimple Markdown with Ecto and Protocols
Simple Markdown with Ecto and Protocols
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
 
[In Control 2010] HTML5
[In Control 2010] HTML5[In Control 2010] HTML5
[In Control 2010] HTML5
 
Making Sense of Twig
Making Sense of TwigMaking Sense of Twig
Making Sense of Twig
 
Html 5
Html 5Html 5
Html 5
 
What you need to know bout html5
What you need to know bout html5What you need to know bout html5
What you need to know bout html5
 
DRYing Up Rails Views and Controllers
DRYing Up Rails Views and ControllersDRYing Up Rails Views and Controllers
DRYing Up Rails Views and Controllers
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
WebSockets with Spring 4
WebSockets with Spring 4WebSockets with Spring 4
WebSockets with Spring 4
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
 
Print this
Print thisPrint this
Print this
 
Coding for entrepreneurs
Coding for entrepreneursCoding for entrepreneurs
Coding for entrepreneurs
 
Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
1 Introduction to PHP Overview This lab walks y.docx
1  Introduction to PHP Overview This lab walks y.docx1  Introduction to PHP Overview This lab walks y.docx
1 Introduction to PHP Overview This lab walks y.docx
 
SINATRA + HAML + TWITTER
SINATRA + HAML + TWITTERSINATRA + HAML + TWITTER
SINATRA + HAML + TWITTER
 

Mais de Razvan Raducanu, PhD

Mais de 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
 
17. delete data
17. delete data17. delete data
17. delete data
 
16. edit data
16. edit data16. edit data
16. edit data
 
15. view single data
15. view single data15. view single data
15. view single data
 
14. add data in symfony4
14. add data in symfony4 14. add data in symfony4
14. add data in symfony4
 
12.doctrine view data
12.doctrine view data12.doctrine view data
12.doctrine view data
 
10. add in Symfony 4
10. add in Symfony 410. add in Symfony 4
10. add in Symfony 4
 
1.symfony 4 intro
1.symfony 4 intro1.symfony 4 intro
1.symfony 4 intro
 
23.simple login with sessions in laravel 5
23.simple login with sessions in laravel 523.simple login with sessions in laravel 5
23.simple login with sessions in laravel 5
 

Último

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Último (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

8. radio1 in Symfony 4

  • 2. • composer create-project symfony/website-skeleton symfony6 • cd symfony6 • php bin/console make:controller >RadioController • composer php/bin server:start • http://localhost:8000/copy
  • 3. Vederea base.html.twig <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>{% block title %}Welcome!{% endblock %}</title> {% block stylesheets %}{% endblock %} </head> <body bgcolor="aquamarine"> {% block body %}{% endblock %} {% block javascripts %}{% endblock %} </body> </html>
  • 4. Vederea radio/index.html.twig {% extends 'base.html.twig' %} {% block title %}Copy!{% endblock %} {% block body %} {{head|raw}} {{ form_start(form) }} {{ form_row(form.radio) }} {{ form_end(form) }} {% endblock %}
  • 5. Vederea radio/output.html.twig {% extends 'base.html.twig' %} {% block title %}Copy!{% endblock %} {% block body %} {{value|raw}} {% endblock %}
  • 6. Controller-ul RadioController <?php namespace AppController; use SymfonyComponentRoutingAnnotationRoute; use SymfonyBundleFrameworkBundleControllerController; use SymfonyComponentHttpFoundationRequest; use SymfonyComponentHttpFoundationResponse; use SymfonyComponentForm; use SymfonyComponentFormExtensionCoreTypeTextType; use SymfonyComponentFormExtensionCoreTypeSubmitType; use SymfonyComponentFormExtensionCoreTypeRadioType; use SymfonyComponentFormExtensionCoreTypeChoiceType;
  • 7. class RadioController extends Controller { /** * @Route("/radio", name="radio") */ public function index(Request $request) { $data=[]; $form=$this->createFormBuilder() ->setAction($this->generateUrl('output'))//se utilizeaza numele controlului adnotat!!! ->setMethod('POST') ->add('radio', ChoiceType::class, array( 'choices' => array('Popescu' => 'Popescu', 'Ionescu' => 'Ionescu', 'Georgescu'=>'Georgescu'), 'expanded' => true, 'multiple' => false, 'label'=>false, )) ->add('submit', SubmitType::class) ->getForm(); $form->handleRequest($request); $data['head']="<h1>Choose:</h1>"; $data['form']=$form->createView();
  • 8. if($form->isSubmitted()){ switch($form->get('radio')->getData()){ case 'Popescu': $data['value'] = 'Popescu'; break; case 'Ionescu'; $data['value'] = 'Ionescu'; break; case 'Georgescu'; $data['value'] = 'Georgescu'; break; default: $data['value'] = 'Vai! vai! vai!'; } } return $this->render('radio/index.html.twig', $data); }
  • 9. /** * @Route("/output", name="output") */ public function output(Request $request) { $var = $request->request->all(); $data['value']="Hello <b>".$var['form']['radio']."</b>!"; return $this->render('radio/output.html.twig', $data); } }