在prestashop中创建新的管理选项卡

时间:2014-07-17 07:57:16

标签: prestashop

这是我的代码。文件mymodule.php:

class Mymodule extends Module {
      public function __construct() {
        $this->name = 'mymodule';
        $this->tab = 'dashboard';
        $this->version = '1.0';
        $this->author = 'My Name';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->l('My Module');
        $this->description = $this->l('My module description.');
        $this->confirmUninstall = $this->l('Are you sure?');
    }

    public function install() {
        return parent::install() && 
               $this->installModuleTab('MyModuleController', 'My Tab', 13);
    }

    public function uninstall() {
        return parent::uninstall() && 
               $this->uninstallModuleTab('MyModuleController'));    
    }

    private function installModuleTab($tabClass, $tabName, $idTabParent) {
        $tab = new Tab();

        foreach (Language::getLanguages() as $language) {
            $tab->name[$language['id_lang']] = $tabName;
        }

        $tab->class_name = $tabClass;
        $tab->module = $this->name;
        $tab->id_parent = $idTabParent;

        if (!$tab->save()) {
            return false;
        }

        return true;
    }

    private function uninstallInternal($class_name) {
        $idTab = Tab::getIdFromClassName($class_name);

        if ($idTab != 0) {
            $tab = new Tab($idTab);
            $tab->delete();

            return true;
        }

        return false;
    }
}

文件MyModuleController.php:

class EraThemeController extends AdminController {

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

    public function display() {
        echo $this->l('This is my tab');
    }
}

安装模块时,这是错误:

属性标签 - >名称为空

在文件类/ ObjectModel.php中的第887行

重新加载管理页面时,已创建选项卡,但单击它时,这是错误:未找到控制器

有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:2)

您的课程应定义为:

class AdminEraThemeController extends ModuleAdminController

同样在你的模块主文件中,名称应该是“AdminEraTheme”,而不是“MyModuleController”

答案 1 :(得分:1)

我使用的是prestashop 1.7,在此版本中,您自己在安装和卸载句柄选项卡上声明$ tabs和pretsashop,我在modules / module_name / module_name.php构造函数中添加以下代码:

class Plevel extends Module
{
    private $c_table='plevel';
    private $c_table_pivot='plevel_excluded';

    public function __construct()
    {
        $this->tabs = array(
        array(
            'name' => 'Price Level', // One name for all langs
            'class_name' => 'AdminPLevel',
            'visible' => true,
            'icon'=>'money',
            'parent_class_name'=>'DEFAULT_MTR'

        ),
        array(
            'name' => 'Price Level List', // One name for all langs
            'class_name' => 'AdminPLevelList',
            'visible' => true,
            'parent_class_name'=>'AdminPLevel',
            'icon'=>'setting',

        ));
        $this->name="plevel";
        $this->tab="dashboard";
        $this->version="1.0.0";
        $this->author="javaheri.ghazaleh@gmail.com";
        $this->need_instance=0;
        $this->ps_versions_compliancy=array('min'=>'1.6','max'=>_PS_VERSION_);
        $this->bootstrap=true;
        $this->context=Context::getContext();
        $this->displayName=$this->l("plevel");
        $this->description=$this->l("change order print page");
        $this->confirmUninstall=$this->l('Are you sure you want to uninstall');
    parent::__construct();
}}

demo