First off, let me explain the title and the reason for this post. I have been diving into MVC and OOP at the same time (my other thread for understanding it for a current project I am working on). That's a hefty learn, i know! OOP is something you need to get your mind around and learn to think in an OOP-way. So that is something I am aware of.

Second: MVC is something a lot of people like to get an understanding of. Knowing that it is not a language, but an architecture. At some point in time we all 'get that', and then new questions arise. That's the reason of my topic 'Flow'.

And please, no bashing. If you're done with the topic, that's ok. Leave it be. For those that want to share a thought, have a question answered, jump in.

The flow of the controller, how and where to authenticate, Where to best apply (interception) filters and how to build them. How to fill forms with POST data. Naming conventions for library classes, class.{purpose}.php?

I think it might be interesting to try and find some common and/or sensible approaches when trying to get the hang of MVC or even building your own, for whatever purposes it might be. Learning, understanding or maybe for production use. I would surely like to have better insight. Studying code and frameworks is one way to go, but using a thread and feedback on eachother seems as a interessting way to go as well.

As an example of stuff I am pondering on: When I filter post_data, I would do it after the entry point, most like in the controller, but what would be the best way to keep the filter(s). If I would want 10 posts from a database, where do I decide to do my LIMIT. Do i use a flexible Query mechanism? And does it also give back results to be used for a pagination?

I would like to have some shared insights on things that may be common to website/application development in an MVC way. What interacts with what and where. Finding a common base for a workable(extendable) MVC. Basically I would like this post to come up with a basic MVC with authentication (SESSION handling might be good too) and some understanding of interception filters.

I know this topic has been discussed on this board a lot, but with PHP5 becoming the mainstream version and MVC catching on, it might be nice to have insights on 'Flow'. Examplecode would ofcourse be ok.

Starting a basic tree:

entrypoint.php (index)
App (or website)

  • Views
    • Index
      • view.php
    • Blog
      • add.php
      • edit.php
      • view.php
    • Comments
      • add.php
      • edit.php
      • view.php
    • Login
      • view.php
  • Controllers
    • indexController.php
    • blogController.php
    • commentsController.php
    • loginController.php
  • Models
    • indexModel.php
    • blogModel.php
    • commentsModel.php
    • loginModel.php
  • Libraries/Helpers (classes)
    • class.authenticate.php
    • class.db.php
    • class.filters.php

The entrypoint.php would in this case instantiate the needed files for the MVC, deconstruct the url (query) and then pass on the action, method and args to the respective controller. From this point on I would have the controller have the add,edit,update, delete functionality.

- Should the model be loaded from the found method before the controller gets called?
- If we would apply a filter on a 'add' call for a controller, do we filter at the model, or the controller?
- Postdata would mostlikely waterfall down to the controller. Where to filter, to handle incomplete or bad postdata?
- If there was a need for authentication, would this be somehwere at entry, to better redirect?