0

我正在尝试将 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 的内容,无论如何,当我在后台单击选项卡时,它仍然是空的。我有调试选项,编译,缓存关闭。

所以请启发我,我应该如何在那里展示任何东西?

4

2 回答 2

0

好吧,我知道这听起来很奇怪,但是您需要使用一些类似的模块,然后阅读他的代码,然后会看到每个模块中的某些方法名称相同。

然后复制它,安装并进行一些更改等。

恕我直言,您错过了需要为 smarty 传递一些数据的标准方法getContent()表单:

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

于 2014-10-17T07:28:22.800 回答
0

我认为问题在于您根本不显示选项卡的内容。

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

$this->renderForm();

进入

echo $this->renderForm();

如果它没有帮助你应该查看这个文档并尝试在没有外部类的情况下进行 - 只尝试使用 Smarty 来显示简单的内容而不使用Tab类或AdminFotoliaSelector

于 2014-08-07T06:14:58.357 回答