module - Prestashop 1.6 创建管理模块

标签 module admin prestashop

您好,我尝试为 prestashop 1.6 创建一个管理模块,但发现一些问题。

我会在主菜单中创建(模块安装后)一个新选项卡,单击它后我会显示一个模板(.tpl),管理员用户可以在其中在 Db 上执行某些操作。

我创建了一个文件夹并将其插入模块文件夹中,在该文件夹中有以下文件:

  • Controller > 管理 > AdminGcbulkController.php
  • gcbulk.tpl
  • gcbulk.php

gcbulk.php:

<?php
    if (!defined('_PS_VERSION_'))
        exit;

require(dirname(__FILE__) . '/gcbulk_header.class.php');

class gcbulk extends Module {

private $page_name = '';

public function __construct() {
    $this->name = 'gcbulk'; // il nome del modulo (lo stesso del file principale)
    $this->tab = 'others'; // sezione in cui va inserito
    $this->version = 0.1;
    $this->author = 'Autore';
    $this->need_instance = 0;
    /*
     * need_instance specifica se un istanza del modulo deve essere caricata
     * quando viene visualizzata la lista dei moduli
       (di norma può essere lasciato a 0)   
     */

    parent::__construct();

    $this->displayName = $this->l('Bulk');
    $this->description = $this->l('Modulo Bulk');

    $this->context->controller->addCSS(($this->_path).'gcbulk.css', 'all');
    //$this->context->controller->addJS(($this->_path).'js/gc_bulk_script.js');

}

public function install() {

    // Install Tabs
    $parent_tab = new Tab();
    // Need a foreach for the language
    $parent_tab->name[$this->context->language->id] = $this->l('Bulk tab');
    $parent_tab->class_name = 'AdminGcbulk';
    $parent_tab->id_parent = 0; // Home tab
    $parent_tab->module = $this->name;
    $parent_tab->add();

    if (!parent::install()
        || !$this->registerHook('admingc')
    );
}

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

    // Uninstall Module
    if (!parent::uninstall())
        return false;
    return true;
}

public function hookadmingc(){

    $this->smarty->assign(array(
        'ciao' => 'hola'
    ));

    return $this->display(__FILE__, 'gcbulk.tpl');
}
}
?>

Controller > 管理 > AdminGcbulkController.php

<?php

class AdminGcbulkController extends ModuleAdminController
{

}

gcbulk.tpl 包含简单的 html。

选项卡的创建工作正常,但我不知道如何在点击后显示 .tpl。实际上在管理内容的右侧返回一个空白页(左侧是菜单)

感谢您的帮助!

最佳答案

Controller 应该实现 renderList 如下:

public function renderList() {
        $return = $this->context->smarty->fetch(_PS_MODULE_DIR_ . '/gcbulk/gcbulk.tpl');             
    return $return;
}  

我建议您将 tpl 移动到此文件夹中:/gcbulk/views/templates/admin/gcbulk.tpl

关于module - Prestashop 1.6 创建管理模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30923077/

相关文章:

javascript - Prestashop:从 smarty 到 JS 的数组

javascript - 我想动态加载到入口点的 Webpack 捆绑模块

wordpress - 为 WordPress 自定义帖子类型创建自定义设置页面

apache - 当有人试图猜测我网站上的管理员目录时,我该如何 react ?

admin - 如何在本地安装 Homebrew 软件包

Prestashop 各州运费

module - 安塞 bool : how to pass multiple commands

javascript - 如何在 'use strict' 模式下跨多个 Node 模块访问我的对象数组作为数据存储?

php - 在 zend 框架中的另一个模块中查看模块的输出

html - 在 Prestashop 上加载页面期间白色闪烁