SlideShare a Scribd company logo
Images in Symfony 4
• composer create-project symfony/website-skeleton symfony11
• cd symfony11
Install doctrine:
• composer require doctrine maker
In .env modificati linia:
DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_
name
astfel:
DATABASE_URL=mysql://root@127.0.0.1:3306/images
Porniti serverul MySQL in XAMPP.
Pentru a crea db flowers, scrieti in fereastra consola:
• php bin/console doctrine:database:create
Pentru a crea o “entitate”(MODELUL!) care va gestiona datele unei tabele (care
urmeaza a fi creata) vom scrie:
php bin/console make:entity Image
Fiecare proprietate a clasei Image poate fi asociata
cu un camp al tabelei image.
Aceasta clasa are definite cateva proprietati private
si metodele publice get si set pentru gestionarea
acestora.
Dorim ca tabela image sa aiba campurile:
- id(int, primary key, autoincrement),
– nume(varchar(100))
– poza(varchar(100))
Modificam /src/Flower/Entity.php astfel:
/src/Flower/Entity.php
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass="AppRepositoryFlowerRepository")
*/
class Flower
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=100)
*/
private $nume;
/**
* @ORMColumn(type="string", length=100)
*/
private $culoare;
public function getId()
{
return $this->id;
}
public function getNume()
{
return $this->nume;
}
public function getPoza()
{
return $this->poza;
}
public function setId($id)
{
return $this->id=$id;
}
public function setNume($nume)
{
return $this->nume=$nume;
}
public function setPoza($poza)
{
return $this->poza=$poza;
}
}
• Pentru a genera tabela image, va trebui sa
generam mai intati fisierul de migrari:
• php bin/console doctrine:migrations:diff
• Pentru a crea efectiv tabela, scriem:
php bin/console doctrine:migrations:migrate
18. images in symfony 4
18. images in symfony 4
• php bin/console make:controller
>DefaultController
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 default/index.html.twig
{% extends 'base.html.twig' %}
{% block body %}
<table>
<tr>
<th>Nume</th>
<th>Poza</th>
<th colspan="3">Actions</th>
</tr>
{% for key in images %}
<tr>
<td>{{ key.nume }}</td>
<td><img src="/images/{{ key.poza }}" width="100" height="100"></td>
<td><a href="{{ app.request.baseUrl() }}/show/{{key.id}}">View</a>
<a href="{{ app.request.baseUrl() }}/edit/{{key.id}}">Edit</a>
<a href="{{ app.request.baseUrl() }}/delete/{{key.id}}" onclick="return
confirm('Are you sure you want to delete this item?');">Delete</a>
</td>
</tr>
{% endfor %}
</table>
<a href="{{ app.request.baseUrl() }}/add">Insert a record</a>
{% endblock %}
Controller-ul DefaultController
<?php
namespace AppController;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyBundleFrameworkBundleControllerController;
use AppEntityImage;
class DefaultController extends Controller
{
/**
* @Route("/", name="default")
*/
public function index()
{
$images = $this->getDoctrine()-> getRepository(Image::class)->findAll();
// replace this example code with whatever you need
return $this->render('default/index.html.twig', array('images'=>$images));
}
}
• In tabela image adaugam:
• In /public cream directorul /images, in care
salvam pozele kali.jpg, lemon.jpg, uaic.jpg,
orange.jpg.

More Related Content

What's hot (19)

PDF
Apostrophe
tompunk
 
PDF
Андрей Юртаев - Improve theming with (Twitter) Bootstrap
DrupalSPB
 
PDF
Laying the proper foundation for plugin and theme development
Tammy Hart
 
PDF
Login and Registration form using oop in php
herat university
 
PDF
Functional testing with capybara
koffeinfrei
 
PDF
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
GetSource
 
PDF
Make your own wp cli command in 10min
Ivelina Dimova
 
PDF
How to make a WordPress theme
Hardeep Asrani
 
PPT
Introduction to ZendX jQuery
dennisdc
 
PDF
Laravel 로 배우는 서버사이드 #5
성일 한
 
TXT
Video
jsola12
 
PDF
Cheap frontend tricks
ambiescent
 
PPTX
15.exemplu complet eloquent view add-edit-delete-search
Razvan Raducanu, PhD
 
PPTX
Build a WordPress theme from HTML5 template @ Telerik
Mario Peshev
 
PDF
Responsive Web Design e a Ubiquidade da Web
Eduardo Shiota Yasuda
 
PDF
Quick ref capybara
fatec
 
PDF
Frameworks da nova Era PHP FuelPHP
Dan Jesus
 
PDF
WordPress Configuration tips
Masharul Pamir
 
PDF
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017
Codemotion
 
Apostrophe
tompunk
 
Андрей Юртаев - Improve theming with (Twitter) Bootstrap
DrupalSPB
 
Laying the proper foundation for plugin and theme development
Tammy Hart
 
Login and Registration form using oop in php
herat university
 
Functional testing with capybara
koffeinfrei
 
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
GetSource
 
Make your own wp cli command in 10min
Ivelina Dimova
 
How to make a WordPress theme
Hardeep Asrani
 
Introduction to ZendX jQuery
dennisdc
 
Laravel 로 배우는 서버사이드 #5
성일 한
 
Video
jsola12
 
Cheap frontend tricks
ambiescent
 
15.exemplu complet eloquent view add-edit-delete-search
Razvan Raducanu, PhD
 
Build a WordPress theme from HTML5 template @ Telerik
Mario Peshev
 
Responsive Web Design e a Ubiquidade da Web
Eduardo Shiota Yasuda
 
Quick ref capybara
fatec
 
Frameworks da nova Era PHP FuelPHP
Dan Jesus
 
WordPress Configuration tips
Masharul Pamir
 
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017
Codemotion
 

Similar to 18. images in symfony 4 (20)

PDF
How to create a basic template
vathur
 
PDF
How To Write Your First Firefox Extension
Robert Nyman
 
PPTX
Building Potent WordPress Websites
Kyle Cearley
 
ODP
Joomla Day UK 2009 Basic Templates
Chris Davenport
 
ODP
Joomla! Day UK 2009 Basic Templates
Andy Wallace
 
PPTX
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
Chandra Prakash Thapa
 
PPTX
9. lower in Symfony 4
Razvan Raducanu, PhD
 
ODP
Codegnitorppt
sreedath c g
 
PPT
Joomla Beginner Template Presentation
alledia
 
DOC
Creating a Simple PHP and MySQL-Based Login System
Azharul Haque Shohan
 
PPTX
Build and save your own Gutenberg Block Patterns
Plasterdog Web Design
 
PDF
Refresh Austin - Intro to Dexy
ananelson
 
PDF
lab56_db
tutorialsruby
 
PDF
lab56_db
tutorialsruby
 
PDF
PhpBB meets Symfony2
Fabien Potencier
 
PPTX
Flask – Python
Max Claus Nunes
 
PPTX
Childthemes ottawa-word camp-1919
Paul Bearne
 
PDF
Installing And Configuration for your Wordpress blog
igorgentry
 
PDF
TurboGears2 Pluggable Applications
Alessandro Molina
 
PPTX
Symfony2 Introduction Presentation
Nerd Tzanetopoulos
 
How to create a basic template
vathur
 
How To Write Your First Firefox Extension
Robert Nyman
 
Building Potent WordPress Websites
Kyle Cearley
 
Joomla Day UK 2009 Basic Templates
Chris Davenport
 
Joomla! Day UK 2009 Basic Templates
Andy Wallace
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
Chandra Prakash Thapa
 
9. lower in Symfony 4
Razvan Raducanu, PhD
 
Codegnitorppt
sreedath c g
 
Joomla Beginner Template Presentation
alledia
 
Creating a Simple PHP and MySQL-Based Login System
Azharul Haque Shohan
 
Build and save your own Gutenberg Block Patterns
Plasterdog Web Design
 
Refresh Austin - Intro to Dexy
ananelson
 
lab56_db
tutorialsruby
 
lab56_db
tutorialsruby
 
PhpBB meets Symfony2
Fabien Potencier
 
Flask – Python
Max Claus Nunes
 
Childthemes ottawa-word camp-1919
Paul Bearne
 
Installing And Configuration for your Wordpress blog
igorgentry
 
TurboGears2 Pluggable Applications
Alessandro Molina
 
Symfony2 Introduction Presentation
Nerd Tzanetopoulos
 
Ad

More from Razvan Raducanu, PhD (20)

PPTX
12. edit record
Razvan Raducanu, PhD
 
PPTX
11. delete record
Razvan Raducanu, PhD
 
PPTX
10. view one record
Razvan Raducanu, PhD
 
PPTX
9. add new record
Razvan Raducanu, PhD
 
PPTX
8. vederea inregistrarilor
Razvan Raducanu, PhD
 
PPTX
7. copy1
Razvan Raducanu, PhD
 
PPTX
6. hello popescu 2
Razvan Raducanu, PhD
 
PPTX
5. hello popescu
Razvan Raducanu, PhD
 
PPTX
4. forme in zend framework 3
Razvan Raducanu, PhD
 
PPTX
3. trimiterea datelor la vederi
Razvan Raducanu, PhD
 
PPTX
2.routing in zend framework 3
Razvan Raducanu, PhD
 
PPTX
1. zend framework intro
Razvan Raducanu, PhD
 
PPTX
17. delete data
Razvan Raducanu, PhD
 
PPTX
16. edit data
Razvan Raducanu, PhD
 
PPTX
15. view single data
Razvan Raducanu, PhD
 
PPTX
14. add data in symfony4
Razvan Raducanu, PhD
 
PPTX
13. view data
Razvan Raducanu, PhD
 
PPTX
12.doctrine view data
Razvan Raducanu, PhD
 
PPTX
11. move in Symfony 4
Razvan Raducanu, PhD
 
PPTX
10. add in Symfony 4
Razvan Raducanu, PhD
 
12. edit record
Razvan Raducanu, PhD
 
11. delete record
Razvan Raducanu, PhD
 
10. view one record
Razvan Raducanu, PhD
 
9. add new record
Razvan Raducanu, PhD
 
8. vederea inregistrarilor
Razvan Raducanu, PhD
 
6. hello popescu 2
Razvan Raducanu, PhD
 
5. hello popescu
Razvan Raducanu, PhD
 
4. forme in zend framework 3
Razvan Raducanu, PhD
 
3. trimiterea datelor la vederi
Razvan Raducanu, PhD
 
2.routing in zend framework 3
Razvan Raducanu, PhD
 
1. zend framework intro
Razvan Raducanu, PhD
 
17. delete data
Razvan Raducanu, PhD
 
16. edit data
Razvan Raducanu, PhD
 
15. view single data
Razvan Raducanu, PhD
 
14. add data in symfony4
Razvan Raducanu, PhD
 
13. view data
Razvan Raducanu, PhD
 
12.doctrine view data
Razvan Raducanu, PhD
 
11. move in Symfony 4
Razvan Raducanu, PhD
 
10. add in Symfony 4
Razvan Raducanu, PhD
 
Ad

Recently uploaded (20)

PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PDF
CHILD RIGHTS AND PROTECTION QUESTION BANK
Dr Raja Mohammed T
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
Quarter1-English3-W4-Identifying Elements of the Story
FLORRACHELSANTOS
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
CHILD RIGHTS AND PROTECTION QUESTION BANK
Dr Raja Mohammed T
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Quarter1-English3-W4-Identifying Elements of the Story
FLORRACHELSANTOS
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 

18. images in symfony 4

  • 2. • composer create-project symfony/website-skeleton symfony11 • cd symfony11 Install doctrine: • composer require doctrine maker In .env modificati linia: DATABASE_URL=mysql://db_user:[email protected]:3306/db_ name astfel: DATABASE_URL=mysql://[email protected]:3306/images Porniti serverul MySQL in XAMPP. Pentru a crea db flowers, scrieti in fereastra consola: • php bin/console doctrine:database:create Pentru a crea o “entitate”(MODELUL!) care va gestiona datele unei tabele (care urmeaza a fi creata) vom scrie: php bin/console make:entity Image
  • 3. Fiecare proprietate a clasei Image poate fi asociata cu un camp al tabelei image. Aceasta clasa are definite cateva proprietati private si metodele publice get si set pentru gestionarea acestora. Dorim ca tabela image sa aiba campurile: - id(int, primary key, autoincrement), – nume(varchar(100)) – poza(varchar(100)) Modificam /src/Flower/Entity.php astfel:
  • 4. /src/Flower/Entity.php <?php namespace AppEntity; use DoctrineORMMapping as ORM; /** * @ORMEntity(repositoryClass="AppRepositoryFlowerRepository") */ class Flower { /** * @ORMId() * @ORMGeneratedValue() * @ORMColumn(type="integer") */ private $id; /** * @ORMColumn(type="string", length=100) */ private $nume;
  • 5. /** * @ORMColumn(type="string", length=100) */ private $culoare; public function getId() { return $this->id; } public function getNume() { return $this->nume; } public function getPoza() { return $this->poza; }
  • 6. public function setId($id) { return $this->id=$id; } public function setNume($nume) { return $this->nume=$nume; } public function setPoza($poza) { return $this->poza=$poza; } }
  • 7. • Pentru a genera tabela image, va trebui sa generam mai intati fisierul de migrari: • php bin/console doctrine:migrations:diff • Pentru a crea efectiv tabela, scriem: php bin/console doctrine:migrations:migrate
  • 10. • php bin/console make:controller >DefaultController
  • 11. 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>
  • 12. Vederea default/index.html.twig {% extends 'base.html.twig' %} {% block body %} <table> <tr> <th>Nume</th> <th>Poza</th> <th colspan="3">Actions</th> </tr> {% for key in images %} <tr> <td>{{ key.nume }}</td> <td><img src="/images/{{ key.poza }}" width="100" height="100"></td> <td><a href="{{ app.request.baseUrl() }}/show/{{key.id}}">View</a> <a href="{{ app.request.baseUrl() }}/edit/{{key.id}}">Edit</a> <a href="{{ app.request.baseUrl() }}/delete/{{key.id}}" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a> </td> </tr> {% endfor %} </table> <a href="{{ app.request.baseUrl() }}/add">Insert a record</a> {% endblock %}
  • 13. Controller-ul DefaultController <?php namespace AppController; use SymfonyComponentRoutingAnnotationRoute; use SymfonyBundleFrameworkBundleControllerController; use AppEntityImage; class DefaultController extends Controller { /** * @Route("/", name="default") */ public function index() { $images = $this->getDoctrine()-> getRepository(Image::class)->findAll(); // replace this example code with whatever you need return $this->render('default/index.html.twig', array('images'=>$images)); } }
  • 14. • In tabela image adaugam: • In /public cream directorul /images, in care salvam pozele kali.jpg, lemon.jpg, uaic.jpg, orange.jpg.