Post by bberry » Tue Nov 15, 2011 12:40 am

I'll make my apologies up front, I'm not a developer. I have been tasked with writing a wiki about the OpenCart file structure for our developers, and although I can generally figure things out, not being a developer I don't know the difference between a model file and a controller file. Can someone give me a brief explanation of the two.

Thanks!!

Newbie

Posts

Joined
Tue Nov 15, 2011 12:31 am

Post by Xsecrets » Tue Nov 15, 2011 12:47 am

well I'll start by saying that none of this is hard and fast. You can do controller functions in models and vice versa, but To adhear to the MVC paradigm it goes as follows.

Controller files. These are the programming logic. Basically any logic functions are handled here. They are also the only files that can be pointed directly to in a link, for example if you have index.php?route=product/product that will call the catalog/controller/product/product.php file.

Model files should be used strictly for interacting with data. This means for the most part any data pulled from or put into the database. It could also mean interacting with a web service as well.

View files should just be presentation. For the most part they are html with php just displaying the variables you passed to them in the controller (variables are passed by setting $this->data['varname'] in the controller) They can of course have loops for array variables, and they may contain small pieces of logic where it makes sense, but we try to keep any major business logic in the controller.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US
Who is online

Users browsing this forum: No registered users and 15 guests