如何在 OpenCart 3 模块管理面板中显示媒体库中的图像选择字段

How to display the image selection field from the media library in the OpenCart 3 module admin panel

如何在 OpenCart 3 模块管理面板中显示媒体库中的图像选择字段?像普通文本框一样尝试过,但它不起作用。

例如,Lats 说我们需要在 Module Featured 中添加和图像。

转到/admin/view/template/extension/module/featured。php

几乎在 public function index() { ... } 内的任何地方(可能在 $this->load->model('setting/module'); 之后和 $this->response->setOutput($this->load->view('extension/module/featured', $data)); 之前)添加以下内容。

之前已经添加了if (isset($this->request->post['top'])) {

if (isset($this->request->post['image'])) {
  $data['image'] = $this->request->post['image'];
} elseif (!empty($module_info)) {
  $data['image'] = $module_info['image'];
} else {
  $data['image'] = '';
}

$this->load->model('tool/image');

if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) {
  $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100);
} elseif (!empty($module_info) && is_file(DIR_IMAGE . $module_info['image'])) {
  $data['thumb'] = $this->model_tool_image->resize($module_info['image'], 100, 100);
} else {
  $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100);
}

$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);

比,在/admin/view/template/extension/module/featured.twig中找到

<div class="form-group">
  <label class="col-sm-2 control-label" for="input-name">{{ entry_name }}</label>
  <div class="col-sm-10">
    <input type="text" name="name" value="{{ name }}" placeholder="{{ entry_name }}" id="input-name" class="form-control" />
    {% if error_name %}
    <div class="text-danger">{{ error_name }}</div>
    {% endif %}
  </div>
</div> 

并在

之后添加
<div class="form-group">
  <label class="col-sm-2 control-label">{{ entry_image }}</label>
  <div class="col-sm-10"><a href="" id="thumb-image" data-toggle="image" class="img-thumbnail"><img src="{{ thumb }}" alt="" title="" data-placeholder="{{ placeholder }}" /></a>
    <input type="hidden" name="image" value="{{ image }}" id="input-image" />
  </div>
</div>

现在应该可以了。