在后台创建新菜单选项卡

时间:2016-03-09 22:26:25

标签: php model-view-controller prestashop-1.6

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

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文档中找不到任何内容!

2 个答案:

答案 0 :(得分:0)

最后,我发现了这种方式:

我在/controllers/admin/AdminQuote.php中创建了类AdminComoteController,它扩展了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(),就像我在其他先前的线程中读到的一样。

答案 1 :(得分:0)

来自smartblog模块的例子。

<?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),
        ),
    );

.
.
.
}