Skip to content

mejoras#1

Open
odiseoteam wants to merge 1 commit into
Rodolphus85:my-frameworkfrom
odiseoteam:my-framework
Open

mejoras#1
odiseoteam wants to merge 1 commit into
Rodolphus85:my-frameworkfrom
odiseoteam:my-framework

Conversation

@odiseoteam
Copy link
Copy Markdown

@odiseoteam odiseoteam commented Feb 23, 2021

@Rodolphus85 hice unas mejoras al framework. Fijate de revisar los cambios para ver si los entendés y luego podés aceptar el pull request.

Modifiqué el nombre del archifo front.php por index.php para que te vayas adaptando a Symfony.

$_SESSION['cart'][$cant_productos] = $request->get('id');

return $response;
return new RedirectResponse($this->urlGenerator->generate('index'));
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rodolphus85 Acá llamo al url generator en vez de poner la url harcodeada.

$head_title = 'Alta de Productos';
$page_title = "Paolo's Commerce - ALTA DE PRODUCTO";

$loader = new \Twig\Loader\FilesystemLoader('../views');
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rodolphus85 Acá saco de todos los controllers la inicialización de Twig, y se lo paso por parámetro.

'productos' => $productos,
'src_images' => $src_images,
'src_images_products' => $src_images_products,
'url_generator' => $this->urlGenerator,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rodolphus85 Inyecto a este servicio el UrlGenerator y se lo paso a la vista.

<div class="row justify-content-md-center">
<div class="col-lg-6 shadow p-3 mb-5 bg-white rounded">
<form action="/front.php/add_products" method="post" enctype="multipart/form-data">
<form action="{{ url_generator.generate('add_products') }}" method="post" enctype="multipart/form-data">
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rodolphus85 Acá uso el UrlGenerator que le habia pasado y genero las rutas. Esto es util porque si cambia la ruta, mientras el nombre de la misma se mantenga, esto va a funcionar.

Comment thread views/index.html.twig
<h5 class="card-title"><a href="{{ url_generator.generate('product', { 'id': producto.id }) }}">{{ producto.name }}</a></h5>
<h5 id="price"> $ {{ producto.price }}</h5>
<a class="btn btn-primary btn-sm" href="/front.php/add_cart?id={{ producto.id }}">Add to cart</a>
<a class="btn btn-primary btn-sm" href="{{ url_generator.generate('add_cart', { 'id': producto.id }) }}">Add to cart</a>
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rodolphus85 Acá además de usar el UrlGenerator, le agregué el id a la ruta add to cart para después poder agarrarlo desde el controller sin usar $_GET.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants