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

PDF
WordCamp Manchester 2016 - Making WordPress Menus Smarter
DOC
20110820 header new style
PPTX
Drupal 7 — Circle theme
PDF
Drupal 8 版型開發變革
PDF
Using Renderless Components in Vue.js during your software development.
PDF
Add loop shortcode
PPTX
Twitter bootstrap
PDF
7 reasons why developers should love Joomla!
WordCamp Manchester 2016 - Making WordPress Menus Smarter
20110820 header new style
Drupal 7 — Circle theme
Drupal 8 版型開發變革
Using Renderless Components in Vue.js during your software development.
Add loop shortcode
Twitter bootstrap
7 reasons why developers should love Joomla!

What's hot (19)

PDF
Apostrophe
PDF
Андрей Юртаев - Improve theming with (Twitter) Bootstrap
PDF
Laying the proper foundation for plugin and theme development
PDF
Login and Registration form using oop in php
PDF
Functional testing with capybara
PDF
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
PDF
Make your own wp cli command in 10min
PDF
How to make a WordPress theme
PPT
Introduction to ZendX jQuery
PDF
Laravel 로 배우는 서버사이드 #5
TXT
Video
PDF
Cheap frontend tricks
PPTX
15.exemplu complet eloquent view add-edit-delete-search
PPTX
Build a WordPress theme from HTML5 template @ Telerik
PDF
Responsive Web Design e a Ubiquidade da Web
PDF
Quick ref capybara
PDF
Frameworks da nova Era PHP FuelPHP
PDF
WordPress Configuration tips
PDF
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017
Apostrophe
Андрей Юртаев - Improve theming with (Twitter) Bootstrap
Laying the proper foundation for plugin and theme development
Login and Registration form using oop in php
Functional testing with capybara
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
Make your own wp cli command in 10min
How to make a WordPress theme
Introduction to ZendX jQuery
Laravel 로 배우는 서버사이드 #5
Video
Cheap frontend tricks
15.exemplu complet eloquent view add-edit-delete-search
Build a WordPress theme from HTML5 template @ Telerik
Responsive Web Design e a Ubiquidade da Web
Quick ref capybara
Frameworks da nova Era PHP FuelPHP
WordPress Configuration tips
Building a theming system with React - Matteo Ronchi - Codemotion Rome 2017
Ad

Similar to 18. images in symfony 4 (20)

PPTX
13. view data
PPTX
14. add data in symfony4
PPTX
15. view single data
PPTX
1.symfony 4 intro
PPTX
10. CodeIgniter vederea inregistrarilor
PPTX
16.mysql stored procedures in laravel
PPTX
8. vederea inregistrarilor
PPTX
13. CodeIgniter vederea inregistrarilor3
PPTX
12. CodeIgniter vederea inregistrarilor2
PPTX
6. Php MongoDB adaugarea unui document
PPTX
19.imagini in laravel5
PPTX
5.hello popescu2
PPTX
15. CodeIgniter editarea inregistrarilor
PPTX
17. delete data
PPTX
19. CodeIgniter imagini in mysql
PPTX
16. CodeIgniter stergerea inregistrarilor
PPTX
14. CodeIgniter adaugarea inregistrarilor
PPTX
10. Imagini in MongoDB
PPTX
11. CodeIgniter vederea unei singure inregistrari
PPTX
9. Php MongoDB cautarea unui document
13. view data
14. add data in symfony4
15. view single data
1.symfony 4 intro
10. CodeIgniter vederea inregistrarilor
16.mysql stored procedures in laravel
8. vederea inregistrarilor
13. CodeIgniter vederea inregistrarilor3
12. CodeIgniter vederea inregistrarilor2
6. Php MongoDB adaugarea unui document
19.imagini in laravel5
5.hello popescu2
15. CodeIgniter editarea inregistrarilor
17. delete data
19. CodeIgniter imagini in mysql
16. CodeIgniter stergerea inregistrarilor
14. CodeIgniter adaugarea inregistrarilor
10. Imagini in MongoDB
11. CodeIgniter vederea unei singure inregistrari
9. Php MongoDB cautarea unui document
Ad

More from Razvan Raducanu, PhD (20)

PPTX
12. edit record
PPTX
11. delete record
PPTX
10. view one record
PPTX
9. add new record
PPTX
PPTX
6. hello popescu 2
PPTX
5. hello popescu
PPTX
4. forme in zend framework 3
PPTX
3. trimiterea datelor la vederi
PPTX
2.routing in zend framework 3
PPTX
1. zend framework intro
PPTX
16. edit data
PPTX
12.doctrine view data
PPTX
11. move in Symfony 4
PPTX
10. add in Symfony 4
PPTX
9. lower in Symfony 4
PPTX
8. radio1 in Symfony 4
PPTX
7. copy2 in Symfony 4
PPTX
PPTX
4.hello popescu
12. edit record
11. delete record
10. view one record
9. add new record
6. hello popescu 2
5. hello popescu
4. forme in zend framework 3
3. trimiterea datelor la vederi
2.routing in zend framework 3
1. zend framework intro
16. edit data
12.doctrine view data
11. move in Symfony 4
10. add in Symfony 4
9. lower in Symfony 4
8. radio1 in Symfony 4
7. copy2 in Symfony 4
4.hello popescu

Recently uploaded (20)

PPTX
Cell Types and Its function , kingdom of life
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Pre independence Education in Inndia.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Lesson notes of climatology university.
PDF
Computing-Curriculum for Schools in Ghana
PDF
Sports Quiz easy sports quiz sports quiz
Cell Types and Its function , kingdom of life
Abdominal Access Techniques with Prof. Dr. R K Mishra
Supply Chain Operations Speaking Notes -ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
01-Introduction-to-Information-Management.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
102 student loan defaulters named and shamed – Is someone you know on the list?
Microbial disease of the cardiovascular and lymphatic systems
O5-L3 Freight Transport Ops (International) V1.pdf
O7-L3 Supply Chain Operations - ICLT Program
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
RMMM.pdf make it easy to upload and study
Pre independence Education in Inndia.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
VCE English Exam - Section C Student Revision Booklet
Lesson notes of climatology university.
Computing-Curriculum for Schools in Ghana
Sports Quiz easy sports quiz sports quiz

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: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
  • 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.