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

Create a basic front-office Controller 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');
}
}

您的文件路径似乎有误,这里有一个简单的版本供您查看:

<?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');

    }
}