how do you trigger a MVC application.
im only used to use procedural coding. since everything are classes, how do i trigger the first method, where should this method be put, and what should the class holding this starter method be called?
thanks
how do you trigger a MVC application.
im only used to use procedural coding. since everything are classes, how do i trigger the first method, where should this method be put, and what should the class holding this starter method be called?
thanks
This is too general of a question. The answer will be subjective, because it can be done in many different ways. Your best bet is to look at a simple, lightweight MVC framework, see how they did it, and use that as a guide. I recommend checking out LightVC.
Generally all requests are routed through an index.php
file. The request url is inspected to figure out what class file to include. For example, a request to /users/login
would fire up Users_Controller
, and then it would execute the login()
method on the Users_Controller
class. This is how most frameworks do it, but like I said, you should look at their source to get a better feel.
Remember an MVC application is like a website, so when the user visits a page in their browser, it will call the methods automatically associated with that page, in the Controller.
MVC applications have routers which based on the URL will call the appropriate controller and function inside.
Take a look at the flowchart of CodeIgniter for example - http://codeigniter.com/user_guide/overview/appflow.html