opencart php custom page without using the “information” feature

后端 未结 2 1565
陌清茗
陌清茗 2020-12-31 11:41

I want to create a custom page in opencart.

I know I can put a custom page in the information section using the admin area however what I would like is a controller

相关标签:
2条回答
  • 2020-12-31 11:59

    It's pretty simple to do to be honest. You need to create a controller for your file, naming based on the folder and filename. For instance common/home.php has

    Class ControllerCommonHome extends Controller
    

    This is accessed using index.php?route=common/home and accesses the index() method. If you want to call another method, for instance foo, you would need to define the method as

    public function foo() {
        // Code here
    }
    

    and would call it using index.php?route=common/home/foo

    As for rendering the view, that's a bit trickier. Basically you need to add all of this to the end of your controller method

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/new_template_file.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/common/new_template_file.tpl';
        } else {
            $this->template = 'default/template/common/new_template_file.tpl';
        }
    
        $this->children = array(
            'common/column_left',
            'common/column_right',
            'common/content_top',
            'common/content_bottom',
            'common/footer',
            'common/header'
        );
    
        $this->response->setOutput($this->render());
    

    Which will render /catalog/view/theme/your-theme-name/template/common/new_template_file.tpl If that file doesn't exist, it will attempt to use the same path in the default theme folder

    I'd recommend you take a look at a few controllers and templates to get your head around where everything comes from properly, but that's the basic gist of how it works

    0 讨论(0)
  • 2020-12-31 12:03

    Please follow this page i hope more use full.

    http://code.tutsplus.com/tutorials/create-a-custom-page-in-opencart--cms-22054

    OpenCart is built using the popular programming MVC pattern. There is also one more element added to this pattern named "L" - a language part - so it's called MVC-L pattern in OpenCart. I won't go into the details of the MVC pattern as it's a very popular and familiar design pattern and we've covered it in great detail in other tutorials.

    0 讨论(0)
提交回复
热议问题