Prestashop 1.7:如何创建基本的自定义管理控制器?

时间:2019-10-03 19:36:51

标签: prestashop prestashop-1.7

我能够在后台创建一个菜单选项卡,但是当我单击它时, Page not found. The controller is missing or invalid.

这是我的控制器的代码-

<?php

class AdminModuleNameConvert extends ModuleAdminController {


    public function __construct()   {
        $this->bootstrap = true;
        parent::__construct();
    }
}

使用ethercreation提供的解决方案,可以加载控制器,但显示给我

Invalid security token

2 个答案:

答案 0 :(得分:1)

尝试宽度:

在您的模块中:modukenameconverter

class modulenameconverter extends Module
{
    public function __construct(Context $context = null)
    {
        $this->name = 'modulenameconverter';
        $this->version = '1';
        $this->bootstrap = true;
        $this->author = 'Stackoverflow';
        $this->displayName = $this->l('modulenameconverter');
        $this->description = $this->l('Module name converter');

        parent::__construct();
    }

    public function install()
    {
        $tab = new Tab();
        $tab->class_name = 'Adminmodulenameconverter';
        $tab->module = 'modulenameconverter';
        $tab->name[1] = 'modulenameconverter';
        $tab->id_parent = 2;
        $tab->active = 1;
        if (!$tab->save()) {
            return false;
        }
        return parent::install();
    }

    public function uninstall()
    {
        $id_tab = (int)Tab::getIdFromClassName('Adminmodulenameconverter');
        $tab = new Tab($id_tab);

        if (Validate::isLoadedObject($tab)) {
            if (!$tab->delete()) {
                return false;
            }
        } else {
            return false;
        }
        return parent::uninstall();
    }
}

module/controllers/admin/AdminModulenameconverterController.php

class AdminNameconverterController extends ModuleAdminController
{
    public function __construct()
    {
        parent::__construct();
        $this->bootstrap = true;
        $this->id_lang = $this->context->language->id;
        $this->default_form_language = $this->context->language->id;
    }

    public function initContent()
    {
        parent::initContent();
    } 
}

致谢

答案 1 :(得分:-1)

我遇到了完全相同的问题,似乎我没有正确配置选项卡参数...我试图为“ $ this-> module”参数传递数组,因此Prestashop找不到该模块,因为在数据库中,链接到选项卡的模块等于“” ...

因此,在这种情况下,我最好的建议是始终检查数据库字段,以查看它们是否正确填充。

总结:总是让最头疼的是最愚蠢的问题... -_-'

相关问题