code teching how to coding under opencart framework
developers please write coding Tips & Tricks for fresh.
0
-
Understanding MVC in Opencart
Controllers
As discussed above, A controller is the first layer of MVC Architecture. So let's take a look at this within the context of our site. We are going to create a new controller to help us gain a better understanding.
- Create a empty
test
directory in controllers directory i.e.,catalog/controller/test
. - Create a
abc.php
PHP File inside thetest
directory i.e.,catalog/controller/test/abc.php
. - Edit the
abc.php
in your IDE and add the following code:
123456789<?php
class
ControllerTestAbc
extends
Controller{
public
function
index()
{
echo
'Hello World'
;
exit
;
}
}
?>
In above example, there are some OpenCart Framework constraints that should be strictly followed by the programmer.
- For a controller class name, It should be Like
Controller(FolderName)(Filename)
. Things to Remember: The first case of folder name and filename must be in uppercase, and don't include file extension as a class name. - The
index()
is the main function that is executed automatically on controller call -
index()
function must be public. - Don't use HTML, JavaScript, or CSS in the controller
Now go to your browser and type the URL:
https://localhost/Opencart/index.php?route=test/abc
Visit to know more Java Training in Pune
0 - Create a empty
Please sign in to leave a comment.
Comments
1 comment