猿问

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

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



HUWWW
浏览 63回答 1
1回答

郎朗坤

例如,拉特说我们需要在精选模块中添加图像。转到/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'])) {&nbsp; $data['image'] = $this->request->post['image'];} elseif (!empty($module_info)) {&nbsp; $data['image'] = $module_info['image'];} else {&nbsp; $data['image'] = '';}$this->load->model('tool/image');if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) {&nbsp; $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100);} elseif (!empty($module_info) && is_file(DIR_IMAGE . $module_info['image'])) {&nbsp; $data['thumb'] = $this->model_tool_image->resize($module_info['image'], 100, 100);} else {&nbsp; $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">&nbsp; <label class="col-sm-2 control-label" for="input-name">{{ entry_name }}</label>&nbsp; <div class="col-sm-10">&nbsp; &nbsp; <input type="text" name="name" value="{{ name }}" placeholder="{{ entry_name }}" id="input-name" class="form-control" />&nbsp; &nbsp; {% if error_name %}&nbsp; &nbsp; <div class="text-danger">{{ error_name }}</div>&nbsp; &nbsp; {% endif %}&nbsp; </div></div>&nbsp;并在后面添加<div class="form-group">&nbsp; <label class="col-sm-2 control-label">{{ entry_image }}</label>&nbsp; <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>&nbsp; &nbsp; <input type="hidden" name="image" value="{{ image }}" id="input-image" />&nbsp; </div></div>现在应该可以了。
随时随地看视频慕课网APP
我要回答