It was not time ago that I realized that those that I consider standards for MVC implementation with PHP are not standards for all. I would be very happy to read different approaches of how to implement MVC architecture with PHP, not just frameworks but the all idea that you are acquainted with and prefer. Not just frameworks but the logic that you accept as the clean one.

Recommended Answers

All 5 Replies

Write a base class with database anything , for M

Smarty for V

Based on your db class, write the code according to your needs for C

Well model is model so it should have layers (that if you drew an UML diagram could make sense) … in my point of view you have obviously the db layer witch has the statements and the functions to use them and return result set , array of results or true false or a single string answer and assigners (that collects data from deferent (if needed) db objects and file system) in order to assign values to an object or generate a list of objects.

To be more accurate a db object has only the connection to the database.. All other works should be done by workers classes of this db object.

the base db class is all of db operation
{
connection
no result query
single result
result set
transaction
close
......
}

do u know db abstract???????????

This is one approach that you mention zark_yoc one other is to have an instance of a db object (could be a child of PDO with what ever methods could do your life easier) and pass it through data operation – workers classes if used directly through controller.

One other logic if you have complex operation logic or even if you want to retrieve list of objects is adding one additional layer of assigners. Passing the instant of the controller (and therefore the available db objects) could use any resource (e.g. file system) or data workers and business logic in order to assign values to an object or a list of objects.

As I wrote I understand that there are many deferent MVC approached to PHP and I am not claiming the best one in any case. I just started this thread in order to have a discussion about these approaches.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.