Php Opencart模块内部错误
我已经开始为Opencart 2.3创建一个简单的“流行产品”模块,只是为了掌握如何在Opencart中创建模块 我遇到了一个问题,当我从后端的extensions部分单击安装模块时,我遇到了一个内部错误页面,我的一些逻辑肯定是不正确的,但我不太确定哪里出了问题。我想知道是否有人能指出我的问题所在 该模块仅用于默认主题。我已将顶部注释掉的文件标记为: 管理文件: 管理控制器文件Php Opencart模块内部错误,php,opencart2.x,opencart-module,opencart2.3,Php,Opencart2.x,Opencart Module,Opencart2.3,我已经开始为Opencart 2.3创建一个简单的“流行产品”模块,只是为了掌握如何在Opencart中创建模块 我遇到了一个问题,当我从后端的extensions部分单击安装模块时,我遇到了一个内部错误页面,我的一些逻辑肯定是不正确的,但我不太确定哪里出了问题。我想知道是否有人能指出我的问题所在 该模块仅用于默认主题。我已将顶部注释掉的文件标记为: 管理文件: 管理控制器文件 <!-- ADMIN CONTROLLER FILE --> <?php class Contro
<!-- ADMIN CONTROLLER FILE -->
<?php
class ControllerModulePopular extends Controller {
private $error = array();
public function index() {
$this->load->language('extension/module/popular');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('extension/module');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
if (!isset($this->request->get['module_id'])) {
$this->model_extension_module->addModule('popular', $this->request->post);
} else {
$this->model_extension_module->editModule($this->request->get['module_id'], $this->request->post);
}
$this->cache->delete('product');
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['entry_name'] = $this->language->get('entry_name');
$data['entry_limit'] = $this->language->get('entry_limit');
$data['entry_width'] = $this->language->get('entry_width');
$data['entry_height'] = $this->language->get('entry_height');
$data['entry_status'] = $this->language->get('entry_status');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['name'])) {
$data['error_name'] = $this->error['name'];
} else {
$data['error_name'] = '';
}
if (isset($this->error['width'])) {
$data['error_width'] = $this->error['width'];
} else {
$data['error_width'] = '';
}
if (isset($this->error['autoplay'])) {
$data['error_autoplay'] = $this->error['autoplay'];
} else {
$data['error_autoplay'] = '';
}
if (isset($this->error['height'])) {
$data['error_height'] = $this->error['height'];
} else {
$data['error_height'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true)
);
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/popular', 'token=' . $this->session->data['token'], true)
);
} else {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/popular', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true)
);
}
if (!isset($this->request->get['module_id'])) {
$data['action'] = $this->url->link('extension/module/popular', 'token=' . $this->session->data['token'], true);
} else {
$data['action'] = $this->url->link('extension/module/popular', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true);
}
$data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true);
if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$module_info = $this->model_extension_module->getModule($this->request->get['module_id']);
}
$data['token'] = $this->session->data['token'];
if (isset($this->request->post['name'])) {
$data['name'] = $this->request->post['name'];
} elseif (!empty($module_info)) {
$data['name'] = $module_info['name'];
} else {
$data['name'] = '';
}
$this->load->model('catalog/product');
$data['products'] = array();
if (isset($this->request->post['product'])) {
$products = $this->request->post['product'];
} elseif (!empty($module_info)) {
$products = $module_info['product'];
} else {
$products = array();
}
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
$data['products'][] = array(
'product_id' => $product_info['product_id'],
'name' => $product_info['name']
);
}
}
if (isset($this->request->post['limit'])) {
$data['limit'] = $this->request->post['limit'];
} elseif (!empty($module_info)) {
$data['limit'] = $module_info['limit'];
} else {
$data['limit'] = 5;
}
if (isset($this->request->post['width'])) {
$data['width'] = $this->request->post['width'];
} elseif (!empty($module_info)) {
$data['width'] = $module_info['width'];
} else {
$data['width'] = 360;
}
if (isset($this->request->post['height'])) {
$data['height'] = $this->request->post['height'];
} elseif (!empty($module_info)) {
$data['height'] = $module_info['height'];
} else {
$data['height'] = 360;
}
if (isset($this->request->post['autoplay'])) {
$data['autoplay'] = $this->request->post['autoplay'];
} elseif (!empty($module_info)) {
$data['autoplay'] = $module_info['autoplay'];
} else {
$data['autoplay'] = 5000;
}
if (isset($this->request->post['status'])) {
$data['status'] = $this->request->post['status'];
} elseif (!empty($module_info)) {
$data['status'] = $module_info['status'];
} else {
$data['status'] = '';
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/module/popular.tpl', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/module/popular')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
$this->error['name'] = $this->language->get('error_name');
}
if (!$this->request->post['width']) {
$this->error['width'] = $this->language->get('error_width');
}
if (!$this->request->post['height']) {
$this->error['height'] = $this->language->get('error_height');
}
return !$this->error;
}
}
这里,您在两个控制器文件中都写入了错误的控制器类。你忘了在那里提到“分机”
在两个(管理和目录)控制器文件中查找并替换以下代码。然后检查一下
查找:
替换:
class ControllerExtensionModulePopular extends Controller {
这里,您在两个控制器文件中都写入了错误的控制器类。你忘了在那里提到“分机”
在两个(管理和目录)控制器文件中查找并替换以下代码。然后检查一下
查找:
替换:
class ControllerExtensionModulePopular extends Controller {
传奇那是我这边缺少鹰眼。谢谢你,传奇人物。那是我这边缺少鹰眼。非常感谢。
<!-- CATALOG CONTROLLER FILE -->
<?php
class ControllerModulePopular extends Controller {
public function index($setting) {
$this->load->language('extension/module/popular');
$data['heading_title'] = $this->language->get('heading_title');
$data['text_tax'] = $this->language->get('text_tax');
$data['button_cart'] = $this->language->get('button_cart');
$data['button_wishlist'] = $this->language->get('button_wishlist');
$data['button_compare'] = $this->language->get('button_compare');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$data['products'] = array();
$product_data = array();
if(isset($setting['limit']) && $setting['limit']!=''){
$setting['limit'] = $setting['limit'];
}
else{
$setting['limit'] = 4;
}
$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.viewed DESC LIMIT " . (int)$setting['limit']);
foreach ($query->rows as $result) {
$product_data[$result['product_id']] = $this->model_catalog_product->getProduct($result['product_id']);
}
$results = $product_data;
if ($results) {
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = $result['rating'];
} else {
$rating = false;
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $rating,
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/extension/module/popular.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/extension/module/popular.tpl', $data);
} else {
return $this->load->view('default/template/extension/module/popular.tpl', $data);
}
}
}
}
<!-- LANGUAGE CONTROLLER FILE -->
<?php
// Heading
$_['heading_title'] = 'Popular Products';
// Text
$_['text_reviews'] = 'Based on %s reviews.';
// Tax
$_['text_tax'] = 'Ex Tax:';
<!-- CATALOG VIEW FILE -->
<h3><?php echo $heading_title; ?></h3>
<div class="row">
<?php foreach ($products as $product) { ?>
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="product-thumb transition">
<div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div>
<div class="caption">
<h4><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></h4>
<p><?php echo $product['description']; ?></p>
<?php if ($product['rating']) { ?>
<div class="rating">
<?php for ($i = 1; $i <= 5; $i++) { ?>
<?php if ($product['rating'] < $i) { ?>
<span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } else { ?>
<span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['price']) { ?>
<p class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-new"><?php echo $product['special']; ?></span> <span class="price-old"><?php echo $product['price']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
<?php } ?>
</p>
<?php } ?>
</div>
<div class="button-group">
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
<button type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-heart"></i></button>
<button type="button" data-toggle="tooltip" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-exchange"></i></button>
</div>
</div>
</div>
<?php } ?>
</div>
class ControllerModulePopular extends Controller {
class ControllerExtensionModulePopular extends Controller {