views:

108

answers:

2

This is my first foray into "appropriately" using an MVC construct (with Code Igniter). I'm hoping some guru can wave her hands and tell me where the following code elements belong. I have them written, I just want to plunk them in the "right" spot!

  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 Code Igniter. 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!

+3  A: 
  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.

GSto
A: 

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.

alex
I believe that everything related to the data input/output should go in the model. That includes sanitation. Therefore, in the model, before it is passed to the controller.
GSto
There is an exception though - what if you want the data "as is" in some parts, but then when you need to print it to the page, you'll use `htmlspecialchars()` to ensure there are no script elements etc in it.
alex