1
我無法真正找到我的問題的直接答案,我無法弄清楚爲什麼一個錯誤將被拋回,當我幾乎99%肯定我已經正確添加了一切。也許一個新的眼睛可以幫助。opencart編輯download.php得到錯誤
問:
我想要一個新列添加到顯示所有已添加了下載的表格,但我得到這個錯誤,無法找出原因。我正在嘗試查看下載是否已附加到產品。
錯誤:
Fatal error: Call to undefined function isUsed() in /customers/b/4/a/athomestudios.net/httpd.www/admin/controller/catalog/download.php on line 178
控制器/目錄/的download.php:
foreach ($results as $result) {
$data['downloads'][] = array(
'download_id' => $result['download_id'],
'name' => $result['name'],
'used' => isUsed($result['download_id']),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'edit' => $this->url->link('catalog/download/edit', 'token=' . $this->session->data['token'] . '&download_id=' . $result['download_id'] . $url, 'SSL')
);
}
模型/目錄/的download.php:
public function isUsed($download_id) {
$query = $this->db->query("SELECT COUNT(*) as `total` FROM " . DB_PREFIX . "product_to_download WHERE download_id = '" . (int)$download_id . "'");
return $query->row['total'];
}
視圖/模板/目錄/ download_list.php:
<?php foreach ($downloads as $download) { ?>
<tr>
<td class="text-center"><?php if (in_array($download['download_id'], $selected)) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $download['download_id']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $download['download_id']; ?>" />
<?php } ?></td>
<td class="text-left"><?php echo $download['name']; ?></td>
<td class="text-center">
<?php
if ($download['used'] == 0) {
echo 'No';
}else{
echo 'Yes';
}
?>
</td>
<td class="text-right"><?php echo $download['date_added']; ?></td>
<td class="text-right"><a href="<?php echo $download['edit']; ?>" data-toggle="tooltip" title="<?php echo $button_edit; ?>" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
</tr>
<?php } ?>
可能是變量範圍問題。嘗試將db連接傳遞給函數。 –
我如何將db連接添加到它? – rackemup420
ahhh你是對的我的朋友!!!我添加了'$ this-> model_catalog_download->'到它的前面,它工作。 – rackemup420