0

Please help me understand how to implement MVC design pattern in PHP and not using any framework

I am making for myself website and I feel like I need to use this design pattern though most of the answers I find after googling arenot satisfactory

6th Sep 2020, 8:38 PM
Kirabo Ibrahim
Kirabo Ibrahim - avatar
1 Odpowiedź
+ 1
MVC is a design pattern that simply means seperating your application model layer from the view layer and using a controller layer as an intermediary. Model - The data needed by the application to function. Entities, database, entity repositories, services. Controller - Intermediary between view and layer. Routing, redirecting, validation..and so on. View - Output shown to users. Template engines, CSS, JavaScript. A basic implementation of MVC can be as simple as this // model.php <?php $data = 42; // view.php <html> <p><?=$data?></p> </html> // empty.php(optional view) <html> <p>Data could not be fetched</p> </html> // controller.php <?php require('model.php'); require(!empty($data) ? 'view.php' : 'empty.php'); For bigger applications, it is advised to use a framework like Laravel(recommended) or Symfony(not suited for beginners). Build website not tools https://www.sololearn.com/post/483610
6th Sep 2020, 8:55 PM
Ore
Ore - avatar