如何在prestshop 1.6中设置自定义搜索器的模块视图


How set module view for custom searcher in prestashop 1.6

我正在尝试将Fotolia Api与Prestashop 1.6.0.9集成。

我已经使用自定义选项卡制作模块,但我不知道如何从模块文件夹设置此选项卡的视图。很遗憾地说,"开发者文档"很糟糕。我找不到任何可行的解决办法。

public function install() {
    if (!parent::install()
            || !$this->registerHook('backOfficeHeader')
            || !$this->registerHook('header')
    ) return false;
    $tab = new Tab();
    $tab->class_name = 'AdminFotoliaSelector';
    $tab->id_parent = 0;
    $tab->module = $this->name;
    $tab->name[(int)(Configuration::get('PS_LANG_DEFAULT'))] = 'Fotolia Selector';
    $tab->add();
    return true;
}

我有大问题,使适当的控制器,现在我只是不能加载任何东西/我不知道如何做到这一点。

<?php
if (!defined('_PS_VERSION_'))
  exit;
class AdminFotoliaSelectorController extends ModuleAdminController {
public $name;
public function __construct() {
    $this->lang = (!isset($this->context->cookie) || !is_object($this->context->cookie)) ? intval(Configuration::get('PS_LANG_DEFAULT')) : intval($this->context->cookie->id_lang);
    parent::__construct();
}

public function initContent() {
    parent::initContent();
    $this->renderForm();
}
public function renderForm() {
    $path = _MODULE_DIR_."fotoliaselector";
    $more = $this->module->display($path, 'views/templates/admin/fotoliaselector.tpl');
    return $more.parent::renderForm();
}

当我尝试die($more)时,它会给我。tpl的内容,无论如何,当我在后台单击tab时,它仍然是空的。我有调试选项打开,编译,缓存关闭。

所以请告诉我,我该如何在那里展示任何东西?

我认为问题是你根本不显示标签的内容。

我不知道module->display方法做什么,但我认为你应该改变initContent()方法行:

$this->renderForm();

echo $this->renderForm();

如果它没有帮助,你应该看看这个文档,并尝试做它没有外部类-只尝试使用Smarty显示简单的内容,而不使用Tab类或AdminFotoliaSelector

我知道这听起来很奇怪,但你需要采取一些类似的模块,并阅读他的代码,将看到一些方法名称在每个模块是相同的。

然后复制,安装和播放一些更改等

Imho你错过了标准方法getContent()形式,你需要传递一些数据的smarty:

public function getContent()
    {
          global $smarty, $cookie;
......
//some code 
......
          $this->_html .= '<script type="text/javascript"   src="'.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>';
          $this->_html .= '<h1>My module title or stuff</h1>';
          $this->_html .= $this->getMyCoolFormOrConfig();
          $smarty->assign('errors', $this->errors);
          $smarty->assign('message', $this->message);
          $this->_html .=  $this->display(__FILE__, 'name_of_tpl_file.tpl');
          return $this->_html;
     }

到BackOffice代码中的简单添加选项卡,如下所示:

        $id_tab=Tab::getIdFromClassName('AdminPayment'); 
        $newtab=new Tab();
        $newtab->id_parent=$id_tab;
        $newtab->module=$this->name;
        $newtab->class_name='MyClassName'; //will be same like MyClassName.php in folder of you module where you need to create you class and extend the AdminTab and from there with function you need to echo you name module
        $newtab->position=Tab::getNbTabs($id_tab)+1;
        $newtab->name[$cookie->id_lang]=$this->l("Name of you stuff");
        $newtab->name[Configuration::get('PS_LANG_DEFAULT')]=$this->l("Name of you stuff");
        $newtab->add();

研究这个文件/controllers/admin/AdminModulesController.php你可以看到每个模块中使用的方法

查看生成模块结构的更大功能(需要注册)https://validator.prestashop.com/generator