【问题标题】:Prestashop 1.6 - Back Office - Smarty - Creating a module that makes a simple blank page?Prestashop 1.6 - Back Office - Smarty - 创建一个制作简单空白页面的模块?
【发布时间】:2014-06-12 13:37:04
【问题描述】:

我正在尝试向我的商店添加一些功能,并且在过去的两天里试图了解 smarty 在 prestashop 中的实际工作方式,或者更确切地说是一般情况。

到目前为止,我已经制作了一个可以安装的模块,安装时它会在左侧菜单上创建一个选项卡,我可以单击该选项卡,它会加载控制器,但这是我卡住的地方......我可以'不知道如何在该状态下显示自定义内容。

我想要的很简单,就是一段文字和一个按钮。单击按钮时,我会做一些事情并记录一些事情,然后将结果显示为一个简单的报告。

所以对于初学者...我想创建带有段落和按钮的页面。

所以我在模块目录中创建了一个名为 priceupdate 的文件夹

这里面有:

/priceupdate.php

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

class PriceUpdate extends Module
{
    public function __construct()
    {
        $this->name = 'priceupdate';
        $this->tab = 'quick_bulk_update';
        $this->version = '0.8';
        $this->author = 'Me';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('Pricing Update');
        $this->description = $this->l('Adds functionality relating to maintaining product my prices.');  

        $this->confirmUninstall = $this->l('Are you sure you would like to uninstall?');

    }

    public function install()
    {
        if (!parent::install()
            || !$this->installModuleTab('AdminPricingUpdate', array(1=>'Pricing Update'), 0))
            return false;
        return true;
    }

    public function uninstall()
    {
        if (!parent::uninstall()
            || !$this->uninstallModuleTab('AdminPricingUpdate', array(1=>'Pricing  Update'), 0))
            return false;
        return true;
    }

    private function installModuleTab($tabClass, $tabName, $idTabParent)

    {    
        $tab = new Tab();

        $tab->name = $tabName;

        $tab->class_name = $tabClass;

        $tab->module = $this->name;

        $tab->id_parent = $idTabParent;

        if(!$tab->save())

            return false;

        return true;

    }

    private function uninstallModuleTab($tabClass)

    {       
        $idTab = Tab::getIdFromClassName($tabClass);

        if($idTab != 0)

        {

            $tab = new Tab($idTab);

            $tab->delete();

            return true;

        }

        return false;

    }

}
?>

还有

/controllers/admin/AdminPricingUpdateController.php

<?php
class AdminPricingUpdateController extends AdminController
{

    public function __construct()

    {

        $this->lang = (!isset($this->context->cookie) || !is_object($this->context->cookie)) ? intval(Configuration::get('PS_LANG_DEFAULT')) : intval($this->context->cookie->id_lang);

        parent::__construct();

    }

    public function display(){

        parent::display();

    }

    public function renderList() {

        return $this->context->smarty->fetch(dirname(__FILE__).'/content.tpl');

    }   
}
?>

这可行,但是我被卡住的地方与 content.tpl 部分有关。为了让它在管理部分的内容区域内创建一个空白页的内容,在 content.tpl 文件中包含什么内容?

我浏览了手册并在论坛上花费了无数小时寻找问题,试图通过分解其他模块来解决问题,但我发现它太复杂了,无法真正理解什么是什么。

如果有人可以帮助我理解这一点,或者向我指出有关此特定主题的信息来源,我们将不胜感激,谢谢!

【问题讨论】:

    标签: module admin prestashop


    【解决方案1】:

    Check that answer

    如果您需要“管理部分内容区域内的空白页内容”,则需要将 content.tpl 设为空白。

    请注意,在我的示例中,如果模板名为“content.tpl”,则不必设置模板的名称。

    【讨论】:

    • 感谢您的意见,非常感谢!但是,如果我将 content.tpl 留空,它只会创建一个没有任何内容的白页。我想将内容添加到后台实际内容区域内的新页面(就像显示所有破折号信息的位置一样 - 所有信息,但带有一个小按钮和一些文字)。我确实查看了您所说的内容,它看起来像是对 prestashop 的修改以添加菜单。我基本上明白它是如何工作的,但唯一的问题不是如果我在我的控制器中有它也只是加载一个白页...... content.tpl 在modules/priceupdate/
    • 这个结构的代码示例会有很大帮助,在 1.6 中确实与后端无关 :(
    • 从上面的链接和 content.tpl 的位置检查我的示例。它在这里完美运行prntscr.com/3s435i
    • 嗯...我尝试像您在前面的示例中那样进行设置,但是当我尝试单击新链接时,它显示Controller not found。我检查了 class_index 文件,AdminPageController 值是否指向确实存在的控制器?有什么想法吗?
    • 好吧,我按照答案中的步骤做了,它奏效了。再次尝试这些步骤,并完全按照描述的方式进行操作。您要么没有创建控制器,要么在创建后没有删除 class_index。
    猜你喜欢
    • 2016-09-28
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多