What is a Controller in Opencart?
A OpenCart Controller is simply a class file that is named in a way that can be associated with a URI.Consider this URI:
rupaknepali.com/index.php?route=account/account
catalog/controller/account/account.php
rupaknepali.com/
admin/index.php?route=sale/customer
Here the file loaded will be:
admin/controller/sale/customer.php
Let's try it: Hello World!
Let's create a simple controller so you can see it in action. Using your text editor, create a file called hello.php, and put the following code in it:Then save the file to your catalog/controllers/account/ folder.
Now visit your site using a URL similar to this:
rupaknepali.com/index.php?route=account/hello
Note: Class names must start with an uppercase letter. In other words, this is valid:
class
ControllerAccountHello extends Controller {
}
?>
class
controllerAccountHelloextends Controller {
}
?>
Functions
In the above example the function name is index(). The "index" function is always loaded by default if the second segment of the URI is empty. Another way to show your "Hello World" message would be this:rupaknepali.com/index.php?route=account/hello/index
Let's try it. Add a new function to your controller:
Now load the following URL to see the comment function:
rupaknepali.com/index.php?route=account/hello/comments
example in opencart, controller example in the opencart, learn opencart by example, how controllers work in opencart?,what is controller in opencart,opwncart
Great help.
ReplyDeleteThank you.