-1

In a lot of MVC frameworks I see that in the controller they load Models like:

$this->load->model('Model');

Is there anything bad about just creating the model objects like so:

$model = new Model();

And am I also supposed to load libraries and helper classes like how it's done in the first example?

502 Error
  • 233
  • 2
  • 12
  • Model is not a class or object. [Model is a layer.](http://stackoverflow.com/a/5864000/727208). And the "proper way" is dependency injection. – tereško May 12 '14 at 19:06

1 Answers1

-1

Follow the convention of the framework.

If the framework uses $this->load->model('Model');, it's most likely because it has some form of autoloader built into it to retrieve the correct class and load it for use.

If you're using $model = new Model(); without first loading in the correct file containing the Model class, your script will fail because Model won't be found.

Axel
  • 10,732
  • 2
  • 30
  • 43
  • I made my own micro MVC framework to learn. I'm check out how others are built, and trying to adapt. I'm using SPL auto loader to load all my classes and see no reason why I would load like that. – 502 Error May 12 '14 at 18:10