Jump to content

Recommended Posts

With the idea of "code to an interface, not an implementation", does this mean that we shouldn't be instantiating models directly within controllers?  For example, if I was accepting user registration information, is it ok for me to instantiate a user model to put the input data into, or is it better to go through some factory class/other method to create my model?

Link to comment
https://forums.phpfreaks.com/topic/218239-object-generation/
Share on other sites

With the idea of "code to an interface, not an implementation", does this mean that we shouldn't be instantiating models directly within controllers?  For example, if I was accepting user registration information, is it ok for me to instantiate a user model to put the input data into, or is it better to go through some factory class/other method to create my model?

 

Generally, most people try to keep their controllers thin.  The controller is the crossing guard - it should pass data along to where it should go (the model, the view), but it shouldn't be responsible for actually manipulating it beyond that.  Even with ORMs, many people create Repository objects to act as a facade in order to keep the model details hidden from the controller.

Link to comment
https://forums.phpfreaks.com/topic/218239-object-generation/#findComment-1132472
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.