Working on a project learning about MVC. My question is how would I setup file wise to display records from the database? For example I have a folder called library, which holds my custom class files. I have one file called menu_class.php that holds the methods to query the database and return all menu records I want to display on my page.
My question is, should I create a second file perhaps called menu_class_view.php that would include methods that I would pass the records found from the database and then have code that takes those db records and display the way I want and then return it back to my controller for display? I assume I need to separate the calls to the database and code used to display those records in html format. If that is the case what is the best way file wise to do this?
Hope this makes sense, thanks!
Consider reading From Flat PHP to Symfony2. “You’ll write a simple application in flat PHP, and then refactor it to be more organized. You’ll travel through time, seeing the decisions behind why web development has evolved over the past several years to where it is now.”
Then read Create your own PHP Framework. “I will gently guide you through the creation of a web framework, one step at a time. At each step, you will have a fully-working framework that you can use as is or as a start for your very own. We will start with simple frameworks and more features will be added with time. Eventually, you will have a fully-featured full-stack web framework.”
As Jeff_Mott is subtly pointing out the best way to learn MVC and design patterns is to familiarize ones self with a modern framework that utilizes the patterns and has very thorough documentation. I prefer Laravel but others Symfony either one is a good start. Both are very well documented and will teach you everything you need to know.
Tutsplus has good tutorials in Code Igniter also based on MVC architecture. You need 3 files basically - controller, a model and your view.
Code Ignitor is quite possibly one of the worst frameworks to use to learn proper, modern architecture of software programs. It provides no support for testing, dependency injection, composer integration, and I could go on and on. It is basically a pile of procedural code using classes as namespace as well. Stay away from code ignitor. Code Ignitor is an antiquated pile of trash. I inherited a project in CI and I want to cut my eyes out having used Laravel and Symfony. No documentation. ecosystem is dry, and the framework itself hardly provides anything useful besides mapping a request to response… useless.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.