2016-03-09 3 views
0

У меня возникли проблемы с добавлением новой вкладки в меню backoffice. я успешно создал его с помощью этой функции (так называемой внутреннего метода установки класса модуля):Создать вкладку нового меню в 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!

ответ

0

Наконец, я считаю так:

Я создал класс AdminQuoteController в /controllers/admin/AdminQuote.php, расширяющий ModuleAdminController. С помощью этого кода внутри:

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

Это работает даже без дисплея объявляют(), Init(), initContent() или __construct(), как я прочитал в других предыдущих потоков.

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

. 
. 
. 
} 
Смежные вопросы