Prestashop 1.7管理模块显示模板

时间:2018-07-18 20:01:09

标签: module prestashop

我的第一个模块有问题。

我创建了一个模块modules / fashion / fashion.php

  <?php

 class Fashion extends Module
{
function __construct()
{
    $this->name = 'fashion';
    $this->tab = 'administration';
    $this->version = 1.0;
            $this->bootstrap = true;
    parent::__construct(); // The parent construct is required for translations

    $this->page = basename(__FILE__, '.php');
    $this->displayName = $this->l('Block Fashion');
    $this->description = $this->l('Add a fashion block');
}

        public function install()
    {
        if (!parent::install() ||
                !$this->registerHook('header')) {
            return false;
        }
        if (Shop::isFeatureActive()) {
            Shop::setContext(Shop::CONTEXT_ALL);
        }

        $tab = new Tab();
        $tab->active = 1;
        $tab->class_name = 'AdminFashionController';
        $tab->name = array();
        foreach (Language::getLanguages(true) as $lang) {
        $tab->name[$lang['id_lang']] = "Fashion";
        }
        $tab->id_parent = (int)Tab::getIdFromClassName('Fashion');
        $tab->module = $this->name;
        return $tab->add();

    }
    public function uninstall()
    {
    // Uninstall Tabs
    $tab = new Tab((int)Tab::getIdFromClassName('Fashion'));
    $tab->delete();

    // Uninstall Module
    if (!parent::uninstall())
        return false;
    }
/**
* Returns module content
*
* @param array $params Parameters
* @return string Content
*/


}

?>

我还创建了modules / fashion / controller / admin / FashionAdminController.php

<?php
class FashionAdminController extends ModuleAdminController
{
public function initContent(){
    parent::initContent();
    $this->setTemplate('fashion.tpl');
}
}
?>

和模块/时尚/视图/模板/admin/fashion.tpl

<!-- Block mymodule -->
 <div id="mymodule_block_left" class="block">
 <h4>Welcome!</h4>
 <div class="block_content">
   <p>Hello,
   {if isset($my_module_name) && $my_module_name}
       {$my_module_name}
   {else}
       World
   {/if}
   !       
</p>   
<ul>
  <li><a href="{$my_module_link}" title="Click this link">Click me!</a></li>
</ul>
</div>
</div>
<!-- /Block mymodule -->

因此,当我在管理面板中单击链接时,会显示“找不到该页面”的显示,这是为什么?我做错了什么?有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

首先,检查菜单(选项卡)是否已在后端创建。

我还认为管理控制器名称应以ADMIN开头:AdminFashionController并将该名称用于选项卡类:

$ tab-> class_name ='AdminFashion';

默认模块中的示例:

public function installTab()
{
    $tab = new Tab();
    $tab->active = 1;
    $tab->class_name = "AdminLinkWidget";
    $tab->name = array();
    foreach (Language::getLanguages(true) as $lang) {
        $tab->name[$lang['id_lang']] = "Link Widget";
    }
    $tab->id_parent = (int)Tab::getIdFromClassName('AdminParentThemes');
    $tab->module = $this->name;
    return $tab->add();
}

您必须添加“活动”并删除“位置”(自动)