Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将模块与多个tpl文件链接?_Php_Opencart_Opencart2.x_Opencart Module - Fatal编程技术网

Php 如何将模块与多个tpl文件链接?

Php 如何将模块与多个tpl文件链接?,php,opencart,opencart2.x,opencart-module,Php,Opencart,Opencart2.x,Opencart Module,是否有任何方法可以添加带有多个模板(.tpl)文件的模块链接 我不确定,但像这样:OpenCart欢迎控制器文件 if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/welcome.tpl')){ $this->template = $this->config->get('config_template') . '/template/m

是否有任何方法可以添加带有多个模板(
.tpl
)文件的模块链接

我不确定,但像这样:OpenCart欢迎控制器文件

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/welcome.tpl')){
   $this->template = $this->config->get('config_template') . '/template/module/welcome.tpl';
   $this->template = $this->config->get('config_template') . '/template/module/new.tpl';
}else{
   $this->template = 'default/template/module/welcome.tpl';}

但是这个例子不起作用。

对于new.tpl,您必须创建一个名为new

方法如下:

  • 创建catalog/controller/custom/new.php

    <?php  
     class ControllerCustomNew extends Controller {
    
     public function index() {
    
       if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/custom/new.tpl')) {
          $this->template = $this->config->get('config_template') . '/template/common/new.tpl';
          } else {
            $this->template = 'default/template/common/new.tpl';
          }
    
          $this->response->setOutput($this->render());
      }
    }
    ?>
    
    
    
  • 在catalog/view/theme/default/template/custom/new.tpl下创建一个新的.tpl文件

    <p>This is new module content</p>
    
    这是新的模块内容

  • 在create catalog/controller/custom/welcome.php下创建自定义欢迎控制器

     <?php  
      class ControllerCustomWelcome extends Controller {
    
       public function index() {
    
          if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/custom/welcome.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/custom/welcome.tpl';
          } else {
           $this->template = 'default/template/custom/welcome.tpl';
          }
    
         $this->children = array(
           'common/column_left',
           'common/column_right',
           'common/content_top',
           'common/content_bottom',
           'common/footer',
           'common/header',
           'custom/new'
          );
    
        $this->response->setOutput($this->render());
       }
      }
     ?>
    
    
    
  • 在catalog/view/theme/default/template/custom/welcome.tpl下创建一个welcome.tpl文件

     <?php echo $header;?>
     <p>This is Welcome module content</p>
     <?php echo $new; ?> <!-- new module content -->
     <?php echo $footer; ?>
    
    
    这是欢迎模块内容

  • 在前端加载欢迎模块,即
    http://yourdomain.com/index.php?route=custom/welcome


  • 你想在welcome.tpl文件上加载new.tpl内容吗?是的,我想在welcome.tpl上用ajax调用new.tpl,但如何?welcome.tpl就是一个例子@AMITMAURYA您正在使用哪个版本的opencart?opencart 1.5.6.4@AMITMAURYATS感谢您的帮助,但不是这个。我想用同一个模块连接两个tpl。如果你想通过ajax使用,url应该是
    http://yourdomain.com/index.php?route=custom/new