Pedro Flores
Developer, happy husband and now a happy father!
Miryam Godoy
CODELAB
24/08/2024
https://meet.google.com/psd-mrvz-gzb
Para ver mejor las presentaciones y la pantalla de ejercicios
hay un link generado para pode acceder al google meet:
https://meet.google.com/psd-mrvz-gzb
Una de las arquitecturas más utilizadas es el Modelo Vista Controlador (MVC), el cual se enfoca en separar las distintas capas de la aplicación para mejorar su mantenimiento y escalabilidad.
M
V
C
M
V
C
Es el patron de diseño de sfotware mas utilizado en el desarrollo web
M
Storage and manages data
M
V
Storage and manages data
Displays data and handles user interactions
M
C
V
Storage and manages data
Displays data and handles user interactions
Connects Model and View
Model
Model
Controller
Model
Controller
View
// src/Entity/Product.php
namespace App\Entity;
use App\Repository\ProductRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
class Product
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column]
private ?int $price = null;
public function getId(): ?int
{
return $this->id;
}
// ... getter and setter methods
}
Model
// src/Controller/ProductController.php
namespace App\Controller;
use App\Entity\Product;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ProductController extends AbstractController
{
#[Route('/product', name: 'create_product')]
public function createProduct(ManagerRegistry $doctrine): Response
{
$entityManager = $doctrine->getManager();
$product = new Product();
$product->setName('Keyboard');
$product->setPrice(1999);
$product->setDescription('Ergonomic and stylish!');
// tell Doctrine you want to (eventually) save the Product (no queries yet)
$entityManager->persist($product);
// actually executes the queries (i.e. the INSERT query)
$entityManager->flush();
return new Response('Saved new product with id '.$product->getId());
}
}
Controller
{# templates/base.html.twig #}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}My Application{% endblock %}</title>
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/css/base.css"/>
{% endblock %}
</head>
<body>
{% block body %}
<div id="sidebar">
{% block sidebar %}
<ul>
<li><a href="{{ path('homepage') }}">Home</a></li>
<li><a href="{{ path('blog_index') }}">Blog</a></li>
</ul>
{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
{% endblock %}
</body>
</html>
View
ORM son las siglas de Object-Relational Mapping, es decir, el mapeo relacional de objetos. Esto significa que va a trasladar los datos de una base de datos relacional, como puede ser MySQL o Postgres, a un sistema de clases y de objetos, donde las clases serían las tablas y los registros pasarían a ser lo equivalente a objetos.
Veamos un ejemplo
By Pedro Flores