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