Skip to main content

code teching how to coding under opencart framework

Comments

1 comment

  • Snehal Harshe

    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.

    1. Create a empty test directory in controllers directory i.e., catalog/controller/test
    2. Create a abc.php PHP File inside the test directory i.e., catalog/controller/test/abc.php.
    3. Edit the abc.php in your IDE and add the following code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <?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.


    1. 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.
    2. The index() is the main function that is executed automatically on controller call
    3. index()  function must be public.
    4. 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

Please sign in to leave a comment.

Powered by Zendesk