我为OC2.3创建了一个新的简单模块,该模块从OC product_special表中获取了一些数据。
我有点堆积,刷新模块模板时我总是黑屏。 我的错误电话是什么,无法从模型查询中获取值?
因此,放置在admin / controller / extension / module中的名为SpecialPrices.php的控制器文件包含以下信息:
<?php
class ControllerExtensionModuleSpecialprices extends Controller {
private $error = array();
public function index() {
..............................
}
// My new function
public function myFunction() {
$this->load->language('extension/module/SpecialPrices');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('extension/module/SpecialPrices');
$products = $this->model_extension_module_SpecialPrices->getProductSpecials($data);
foreach ($products as $product) {
$data['products'][] = array(
'product_id' => $product['product_id'],
'price' => $product_info['price']
);
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_title'] = $this->language->get('text_title');
$data['text_product_id'] = $this->language->get('text_product_id');
$data['text_price'] = $this->language->get('text_price');
$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 /SpecialPrices', $data));
}
...........
我在admin / model / extension /模块中名为SpecialPrices.php的模型文件包含...
public function getProductSpecials($data) {
$sql = "SELECT * FROM `" . DB_PREFIX ."product_special` ";
$query = $this->db->query($sql);
return $query->rows;
}
在我的模板SpecialPrices.tpl中,该文件在路径admin / view / template / extension / module中创建,试图从上述查询中获取值
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
.......
<?php echo $product_id; ?>
<?php echo $price; ?>
.........
//文字 $ _ ['text_extension'] ='扩展名'; $ _ ['text_success'] ='成功:您已经在产品中插入了批量特惠价!'; $ _ ['text_edit'] ='编辑批量特惠价格模块';
答案 0 :(得分:0)
乍看之下,您在module
之后留了空格:
$this->response->setOutput($this->load->view('extension/module /SpecialPrices', $data));
必须是:
$this->response->setOutput($this->load->view('extension/module/SpecialPrices', $data));
您在错误日志中收到哪些错误?
在控制器文件中,应将代码放置到public function index() {//your code}
或在某个位置调用函数。我看不到您在哪里打电话。
如果您有在tpl中调用的数据数组,则应按以下步骤操作:
<?php foreach ($products as $product) { ?>
<?php echo $product['product_id']; ?>
<?php echo $product['price']; ?>
<?php }?>
好。编辑并工作:
控制器mymodule.php
:
<?php
class ControllerExtensionModuleMymodule extends Controller {
public function index() {
$this->load->language('extension/module/mymodule');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('extension/module/mymodule');
$products = $this->model_extension_module_mymodule->getProductSpecials();
foreach ($products as $product) {
$data['products'][] = array(
'product_id' => $product['product_id'],
'price' => $product['price']
);
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_title'] = $this->language->get('text_title');
$data['text_product_id'] = $this->language->get('text_product_id');
$data['text_price'] = $this->language->get('text_price');
$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/mymodule', $data));
}
}
模型... mymodule.php
:
<?php
class ModelExtensionModuleMymodule extends Model {
public function getProductSpecials() {
$sql = "SELECT * FROM `" . DB_PREFIX ."product_special` ";
$query = $this->db->query($sql);
return $query->rows;
}
}
mumodule.tpl
:
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<?php foreach ($products as $product) { ?>
<?php echo $product['product_id']; ?>
<?php echo $product['price']; ?>
<?php }?>
</div>
</div>
</div>
<?php echo $footer; ?>
添加文件后,不要忘记在admin> setting> usergroup> Administrator
中设置权限