Skip to content

Commit 4aa1c28

Browse files
Merge pull request #5 from tonicospinelli/05-layout
refactoring: isolating application layout
2 parents cd88321 + 1b3087e commit 4aa1c28

File tree

3 files changed

+75
-64
lines changed

3 files changed

+75
-64
lines changed

templates/layout.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title><?php echo $title ?></title>
5+
</head>
6+
<body>
7+
<?php echo $content ?>
8+
</body>
9+
</html>

templates/products/list.php

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1-
<html>
2-
<head></head>
3-
<body>
4-
<?php if (null !== $errormsg): ?>
5-
<div class="alert error"><?php echo $errormsg; ?> </div>
6-
<?php elseif (isset($product)): ?>
7-
<div class="alert success"><?php echo $successmsg; ?></div>
8-
<?php endif; ?>
9-
<h3>Products</h3>
10-
<table>
11-
<thead>
12-
<tr>
13-
<th>ID</th>
14-
<th>PRODUCT</th>
15-
<th>UNIT PRICE</th>
16-
<th>STOCK</th>
17-
<th>ACTIONS</th>
18-
</tr>
19-
</thead>
20-
<tbody>
21-
<?php foreach ($products as $product): ?>
1+
<?php $title = 'List of Producst' ?>
2+
3+
<?php ob_start() ?>
4+
<h3>Products</h3>
5+
<?php if (null !== $errormsg): ?>
6+
<div class="alert error"><?php echo $errormsg; ?> </div>
7+
<?php elseif (isset($product)): ?>
8+
<div class="alert success"><?php echo $successmsg; ?></div>
9+
<?php endif; ?>
10+
<table>
11+
<thead>
2212
<tr>
23-
<td><?php echo $product['id']; ?> </td>
24-
<td><?php echo $product['name']; ?> </td>
25-
<td><?php echo $product['unit_price']; ?> </td>
26-
<td><?php echo $product['stock']; ?> </td>
27-
<td><?php echo removeUrl('product.php', $product['id']); ?> </td>
13+
<th>ID</th>
14+
<th>PRODUCT</th>
15+
<th>UNIT PRICE</th>
16+
<th>STOCK</th>
17+
<th>ACTIONS</th>
2818
</tr>
29-
<?php endforeach; ?>
30-
</tbody>
31-
</table>
32-
</body>
33-
</html>
19+
</thead>
20+
<tbody>
21+
<?php foreach ($products as $product): ?>
22+
<tr>
23+
<td><?php echo $product['id']; ?> </td>
24+
<td><?php echo $product['name']; ?> </td>
25+
<td><?php echo $product['unit_price']; ?> </td>
26+
<td><?php echo $product['stock']; ?> </td>
27+
<td><?php echo removeUrl('product.php', $product['id']); ?> </td>
28+
</tr>
29+
<?php endforeach; ?>
30+
</tbody>
31+
</table>
32+
<?php $content = ob_get_clean() ?>
33+
34+
<?php include __DIR__.'/../layout.php' ?>

templates/wishlists/list.php

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
<html>
2-
<head></head>
3-
<body>
4-
<?php if (null !== $errormsg): ?>
5-
<div class="alert error"><?php echo $errormsg; ?> </div>
6-
<?php elseif (isset($wishItem)): ?>
7-
<div class="alert success"><?php echo $successmsg; ?></div>
8-
<?php endif; ?>
9-
<h3>My Wish List</h3>
10-
<table>
11-
<thead>
12-
<tr>
13-
<th>ID</th>
14-
<th>PRODUCT</th>
15-
<th>STATUS</th>
16-
<th>ACTIONS</th>
17-
</tr>
18-
</thead>
19-
<tbody>
20-
<?php foreach ($wishlist as $wish): ?>
1+
<?php $title = 'My Wish List' ?>
2+
3+
<?php ob_start() ?>
4+
<h3><?php echo $title;?></h3>
5+
<?php if (null !== $errormsg): ?>
6+
<div class="alert error"><?php echo $errormsg; ?> </div>
7+
<?php elseif (isset($wishItem)): ?>
8+
<div class="alert success"><?php echo $successmsg; ?></div>
9+
<?php endif; ?>
10+
<table>
11+
<thead>
2112
<tr>
22-
<td><?php echo $wish['id']; ?> </td>
23-
<td><?php echo $wish['product_name']; ?> </td>
24-
<?php if ($wish['product_stock'] == 0): ?>
25-
<td>Not Available</td>
26-
<?php else: ?>
27-
<td>Available</td>
28-
<?php endif; ?>
29-
<td><?php echo removeUrl('wishlist.php', $wish['id'], ['email' => $_GET['email']]); ?> </td>
13+
<th>ID</th>
14+
<th>PRODUCT</th>
15+
<th>STATUS</th>
16+
<th>ACTIONS</th>
3017
</tr>
31-
<?php endforeach; ?>
32-
</tbody>
33-
</table>
34-
</body>
35-
</html>
18+
</thead>
19+
<tbody>
20+
<?php foreach ($wishlist as $wish): ?>
21+
<tr>
22+
<td><?php echo $wish['id']; ?> </td>
23+
<td><?php echo $wish['product_name']; ?> </td>
24+
<?php if ($wish['product_stock'] == 0): ?>
25+
<td>Not Available</td>
26+
<?php else: ?>
27+
<td>Available</td>
28+
<?php endif; ?>
29+
<td><?php echo removeUrl('wishlist.php', $wish['id'], ['email' => $_GET['email']]); ?> </td>
30+
</tr>
31+
<?php endforeach; ?>
32+
</tbody>
33+
</table>
34+
<?php $content = ob_get_clean() ?>
35+
36+
<?php include __DIR__.'/../layout.php' ?>

0 commit comments

Comments
 (0)