创建一个基本的前台控制器Prestashop 1.7

时间:2017-10-26 09:52:31

标签: prestashop prestashop-1.7

我是初学者,我正在学习如何创建一个前台控制器。我编写了以下代码,但在加载页面时没有显示任何内容。我还没有在我的模块代码中提及它。我该怎么办?

<?php

if (!defined('_PS_VERSION_')) {
exit;
}

class AbcMyPageModuleFrontController extends ModuleFrontController
{
  public function initContent()
{
    parent::initContent();
    $this->setTemplate('module:abc/views/templates/front/myFirst.tpl');
}
}

1 个答案:

答案 0 :(得分:0)

你的文件路径似乎有误,这里只是一个简单的版本:

<?php

// Edit name and class according to your files, keep camelcase for class name.
require_once _PS_MODULE_DIR_.'modulename/modulename.php';

class ModuleNameAjaxModuleFrontController extends ModuleFrontController
{
    public function initContent()
    {

        $module = new ModuleName;

        // Usefull vars derivated from getContext
        $context = Context::getContext();
        $cart = $context->cart;
        $cookie = $context->cookie;
        $customer = $context->customer;
        $id_lang = $cookie->id_lang;


        // Template path : modules/modulename/views/template/front/template.tpl
        // Just put some vars in your template
        $this->context->smarty->assign(array('myvar'=>'thevalue'));
        $this->setTemplate('template.tpl');

    }
}