Practice on Controllers and Views in MVC

Задание 1

Create a controller Product, in whose constructor the following array will be set:

php<?php
  $this->products = [
    1 => [
      'name'     => 'product1',
      'price'    => 100,
      'quantity' => 5,
      'category' => 'category1',
    ],
    2 => [
      'name'     => 'product2',
      'price'    => 200,
      'quantity' => 6,
      'category' => 'category2',
    ],
    3 => [
      'name'     => 'product3',
      'price'    => 300,
      'quantity' => 7,
      'category' => 'category2',
    ],
    4 => [
      'name'     => 'product4',
      'price'    => 400,
      'quantity' => 8,
      'category' => 'category3',
    ],
    5 => [
      'name'     => 'product5',
      'price'    => 500,
      'quantity' => 9,
      'category' => 'category3',
    ],
  ]
?>
Задание 2

In the controller Product, create an action show, which will show information about one product. Let this action handle addresses of the following type: /product/:n/, where the parameter will be the product number in the array. Make it so that accessing such addresses displays via var_dump the data of that product that was requested via the address string.

Задание 3

Add a view to the created action. Use the following markup for this:

html<h1>Product "product1" from category "category1"</h1>
<p>
  Price: 100$, quantity: 5
</p>
<p>
  Cost (price * quantity): 500$
</p>

The data in this markup corresponds to the first product. Make it so that the view shows the data of the product that was requested via the address string.

Задание 4

In the controller Product, create an action all, which will display a list of all products in the form of an HTML table. Let this action handle the address /products/all/.