I've been trying to get my head around MVC frameworks recently, since I'm starting my first Web Dev job in a few weeks and I've not really understood them up till now.
I understand the basics of them, but there are a few things that are confusing me. One of them is folder structure.
Now I know that different frameworks and different examples have different structures, so I'm really just looking for a simple example of how this could be all set out.
Up till now I've been playing around with some "design your own simple framework" tutorials, and I ended up with something along the lines of:
Which works as such, with the following example URL:
- Loads Index.php page. This sorts out what controller to call.
- Loads ItemController.php - Which in turn, loads ItemTemplate.php Template
- Calls view() method of ItemController with the parameter of "1" - view(1)
- That method access the Item model and does various stuff
- Any template methods are called, eg. $Template->view() to display the view HTML
- Template is rendered, using $Template->render() method
Now, I know that's probably a poor way of doing it, but it works for the simple-ish application I've been making.
Anywho, I've come to the point now where I realised that I'm going to be needing quite longer URLs for another project sometimes, but I'm not sure how to go about implenting it.
For example, one URL which might be access could be something like:
Where I would want the User Controller to be loaded, the view() method to be called with "9" as the parameter.
But other times the URL might be something like:
And I can't see any way of doing that without calling an activities() method and then doing various switch statements until it gets to the required content. Which seems like it defeats the point of making it easier to use and develop with.
I've seen one or two example with lots of sub folders, but I'm yet to find any actually good and informative documentation or examples on any of this, so it's all guess work.
If you were going to have longer URLs like that, what would you suggest as to how to structure the files? And how do you get around the issue that sometimes you will be wanting a /controller/action/parameter whereas others you'll just be wanting /controller/content/subcontent/subcontent?
Basically: I'm confused and I can't find any decent explanations for any of this.