Should I call redirect() from within my Controller or Model in an MVC framework?

Posted by justinl on Stack Overflow See other posts from Stack Overflow or by justinl
Published on 2011-01-05T06:38:26Z Indexed on 2011/01/05 6:53 UTC
Read the original article Hit count: 227

Filed under:
|
|
|
|

I'm using the MVC PHP framework Codeigniter and I have a straight forward question about where to call redirect() from: Controller or Model?

Scenario:
A user navigates to www.example.com/item/555. In my Model I search the item database for an item with the ID of 555. If I find the item, I'll return the result to my controller. However, if an item is not found, I want to redirect the user somewhere. Should this call to redirect() come from inside the model or the controller? Why?

© Stack Overflow or respective owner

Related posts about mvc

Related posts about codeigniter