在后台创建新的菜单选项卡


Create New Menu Tab In The Backoffice

我在后台菜单中添加新选项卡时遇到一些问题。我用这个函数成功创建了它(称为模块类的内部安装方法):

public function createMenuTab() {
    $tab = new Tab();
    $tab->module = $this->name;
    $tab->class_name = 'AdminQuote';
    $tab->id_parent = 0;
    $tab->active = 1;
    foreach (Language::getLanguages(false) as $l)
        $tab->name[$l['id_lang']] = 'Gestione Preventivi';
    return (bool)$tab->add();
}

但是现在我不知道如何显示视图。

我将类 AdminQuoteController 放在/controllers/admin/AdminQuote 中.php它只是扩展了 ModuleAdminController。

我现在应该怎么做才能显示视图?我在 PS 文档中没有找到任何东西!

有来自智能博客模块的示例。

<?php
class AdminImageTypeController extends ModuleAdminController
{
    public function __construct()
    {
        $this->table = 'smart_blog_imagetype';
        $this->className = 'BlogImageType';
        $this->module = 'smartblog';
        $this->lang = false;
        $this->context = Context::getContext();
        $this->bootstrap = true;
        $this->fields_list = array(
            'id_smart_blog_imagetype' => array(
                'title' => $this->l('Id'),
                'width' => 100,
                'type' => 'text',
            ),
            'type_name' => array(
                'title' => $this->l('Type Name'),
                'width' => 350,
                'type' => 'text',
            ),
            'width' => array(
                'title' => $this->l('Width'),
                'width' => 60,
                'type' => 'text',
            ),
            'height' => array(
                'title' => $this->l('Height'),
                'width' => 60,
                'type' => 'text',
            ),
            'type' => array(
                'title' => $this->l('Type'),
                'width' => 220,
                'type' => 'text',
            ),
            'active' => array(
                'title' => $this->l('Status'),
                'width' => 60,
                'align' => 'center',
                'active' => 'status',
                'type' => 'bool',
                'orderby' => false
            )
        );
        parent::__construct();
    }
    public function renderForm()
    {
        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('Blog Category'),
            ),
            'input' => array(
                array(
                    'type' => 'text',
                    'label' => $this->l('Image Type Name'),
                    'name' => 'type_name',
                    'size' => 60,
                    'required' => true,
                    'desc' => $this->l('Enter Your Image Type Name Here'),
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('width'),
                    'name' => 'width',
                    'size' => 15,
                    'required' => true,
                    'desc' => $this->l('Image height in px')
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Height'),
                    'name' => 'height',
                    'size' => 15,
                    'required' => true,
                    'desc' => $this->l('Image height in px')
                ),
                array(
                    'type' => 'select',
                    'label' => $this->l('Type'),
                    'name' => 'type',
                    'required' => true,
                    'options' => array(
                        'query' => array(
                            array(
                                'id_option' => 'post',
                                'name' => 'Post'
                            ),
                            array(
                                'id_option' => 'Category',
                                'name' => 'category'
                            ),
                            array(
                                'id_option' => 'Author',
                                'name' => 'author'
                            )
                        ),
                        'id' => 'id_option',
                        'name' => 'name'
                    )
                ),
                array(
                    'type' => 'switch',
                    'label' => $this->l('Status'),
                    'name' => 'active',
                    'required' => false,
                    'is_bool' => true,
                    'values' => array(
                        array(
                            'id' => 'active',
                            'value' => 1,
                            'label' => $this->l('Enabled')
                        ),
                        array(
                            'id' => 'active',
                            'value' => 0,
                            'label' => $this->l('Disabled')
                        )
                    )
                )
            ),
            'submit' => array(
                'title' => $this->l('Save'),
            )
        );
        if (!($BlogImageType = $this->loadObject(true)))
            return;
        $this->fields_form['submit'] = array(
            'title' => $this->l('Save   '),
        );
        return parent::renderForm();
    }
    public function renderList()
    {
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        return parent::renderList();
    }
    public function initToolbar()
    {
        parent::initToolbar();
    }
}
class BlogImageType extends ObjectModel
{
    public $id_smart_blog_imagetype;
    public $type_name;
    public $width;
    public $height;
    public $type;
    public $active = 1;
    public static $definition = array(
        'table' => 'smart_blog_imagetype',
        'primary' => 'id_smart_blog_imagetype',
        'multilang' => false,
        'fields' => array(
            'width' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => true),
            'height' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => true),
            'type_name' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true),
            'type' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true),
            'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
        ),
    );
.
.
.
}

最后,我发现这种方式:

我在/controllers/admin/AdminQuote 中创建了类 AdminQuoteController.php它扩展了 ModuleAdminController。里面有这段代码:

class AdminQuoteController extends ModuleAdminController {
    public function renderList() {
        return $this->context->smarty->fetch(_PS_MODULE_DIR_.'preventivi/views/templates/admin/content.tpl');
    }
}

即使没有声明 display()、init()、initContent() 或 __construct(),就像我在前面的其他线程中读到的那样,这也可以工作。