【问题标题】:How set module view for custom searcher in prestashop 1.6如何在 prestashop 1.6 中为自定义搜索器设置模块视图
【发布时间】:2014-08-06 14:54:48
【问题描述】:

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

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

【问题讨论】:

    标签: php smarty prestashop-1.6


    【解决方案1】:

    我认为问题在于您根本不显示标签的内容。

    我不知道module-&gt;display 方法是做什么的,但我认为你应该在initContent() 方法行中进行更改:

    $this->renderForm();
    

    进入

    echo $this->renderForm();
    

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

    【讨论】:

    • 您好,感谢四位您的重播。 Echo 在标​​头中的某个随机位置注入我的代码,破坏了所有 html 结构。 module-&gt;display 返回 .tpl 文件的内容。我试图了解这是如何工作的,但这对我来说很糟糕,我应该使用哪个挂钩来附加到我的自定义创建的选项卡上?我应该创建新的并将其加载到 TPL 中,如果是,我应该如何以正确的方式将此 TPL 提供给模块?前端示例没关系,但对于前台。我在后台使用 in 时遇到问题。 Pozdrawiam ;) (问候)
    • @amnestia 抱歉,我无法为您提供更多帮助。也许其他了解 Prestashop 的人会。
    【解决方案2】:

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

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

    恕我直言,您错过了需要为 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-04-06
      • 1970-01-01
      • 2016-09-28
      • 1970-01-01
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      相关资源
      最近更新 更多