⊗ppMVUFmCVT 13 of 35 menu

Practice on Controllers and Views in MVC

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

<?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', ], ] ?>

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.

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

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

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

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline