⊗ppMVUFmRtg 7 of 35 menu

Routing in MVC in PHP

Now you need to get acquainted with such a concept as routing. It represents a mechanism by which you can call a specific action of a specific controller through the browser's address bar.

Routing settings are stored in the file /project/config/routes.php and are an array of objects of the class \Core\Route. The constructor of this class takes as the first parameter the URI, upon request of which the corresponding method of the corresponding controller will be called. The controller name and the action name are specified by the second and third parameters. In this case, the controller name is specified in lowercase.

Let's add two routes for example (i.e., routes): the first one when accessing the address /my-page1/ will call the method show1 of the controller page, and the second one - the method show2 of the same controller:

<?php use \Core\Route; return [ new Route('/my-page1/', 'page', 'show1'), new Route('/my-page2/', 'page', 'show2'), ]; ?>

Based on the theory received in the previous lessons, make a controller TestController with actions act1, act2 and act3. Make three routes that set the addresses by which it will be possible to access these actions. Test the code you created by accessing each of the actions in turn through the address bar.

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