Question

This is my first foray into using an MVC construct (CodeIgniter). I'm hoping someone can tell me where the following elements belong. I have them written; I just want to make sure they're placed properly in their respective locations. This is how my application will run:

  1. Call a DB and see if we have a user signed up
  2. Route to a signup page
  3. Route to the main preferences page for existing users
  4. Make DB queries for producing a new user
  5. Make update queries when users change their preferences

The service being provided is a cron job cycling every 10 minutes, which I still have written outside of CodeIgniter. Is this something I should/could add to the logic somewhere? It pings Twitter, and does stuff with any new tweets. Let me know if I can clarify any part of this!

Was it helpful?

Solution

  1. Model
  2. Controller
  3. Controller
  4. Model
  5. Model

Rule of thumb: if it involves the database or the state of the application, it belongs in a model. If it is HTML or presentation logic, it belongs in a view. Controllers handle the rest of the logic, and help link the views and models together.

OTHER TIPS

There are a lot of other things that come up too:

  • Where should I sanitise data? As it comes from the model - in the controller or finally before I view? I do it generally in the view if it's something like htmlspecialchars() (though I'm sure others might disagree).

Wikipedia has a very good article.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top