Hi everyone, me Rupak Nepali. In our fifth video, we describe OpenCart objects and list of methods. Today in our sixth video I am going to describe OpenCart framework code flow and how request and response are handled by OpenCart. Describe how MVCL works in OpenCart which will create a good foundation to start programming in OpenCart.
“OpenCart theme and Module development” book say “OpenCart is an e-commerce shopping cart application built with its own in-house framework which uses MVCL (Model, view, controller, and language)pattern. Thus, each module in OpenCart also follows the MVCL pattern. The controller creates logic and gathers data from the model and it passes data to display in the view.”
OpenCart is based on this MVCL pattern. Let’s see what is MVCL pattern:
- The user request to the controller through URL,
- Controller loads the language and set the variable for any text used in the data.
- If data is needed from the database controller loads the model, ask for result and model send back results, then controller set results to data.
- All these data are sent to View which renders and show the output.
In the catalog and admin directories, you can see a tree structure of MVCL so whenever we create modules or pages we follow these directories structure:
- Controller – Controller loads the language and set the variable for any text used in the data. If data is needed from the database controller loads the model, ask for result and model send back results, then controller set results to data.
- Model – Database layer – All calls to the database are done. It is to structure DB calls so that all other files have access to the same DB queries.
- View – Presentation/Template/display layer – This is where the HTML and designing are done in the respective
- Language – Localization/Language – This is layer is to make the translation easy, variables and text are assigned and these folder files are translated to the respective language with the same variables name.
OpenCart handles each request with
It’s that easy! Yes!
- Each request executes a front controller file
- The routing system determines which Controller class index method will be executed based on information from the request and routing URLyou’ve passed.
- Returns the appropriate Response object.
Let’s see some example
Here “route=account/login”, it means that the controller to find in Opencart is catalog/controller/account/login.php as there is no third one so by default the method is index().
Here “route=account/return/add”, it means that the controller to find in Opencart is catalog/controller/account/return.php and method is add().
- The controller name must be like Controller + directory path+ file name
- If your file name contains (_) underscore then no need to add in controller name.
- The controller class must extend the parent class i.e.Controller
Let’s check the code. Let say the user request the same URL http://webocreation.loc/index.php?route=account/login
With route=account/login, the controller to process is ControllerAccountLoginclass and index method.
So, by defining MVCL we completed our fifth video, hope you liked it. As always please don’t forget to post your questions or comments so that I can add extra topics or things that I need to develop which will help to develop the quality of videos series. You can follow at my twitter account
In the next video, the real fun program begins “Hello World” Opencart module. So, see you in the