Create Download CMS Page on OpenCart 2.x Quick and Dirty

~/www/catalog/view/theme/default/template/download/download.tpl

 

<?php echo $header; ?>
<?php echo $content_top; ?>
<div class="container">
 <div class="row"><?php echo $column_left; ?>
   <?php if ($column_left && $column_right) { ?>
   <?php $class = 'col-sm-6'; ?>
   <?php } elseif ($column_left || $column_right) { ?>
   <?php $class = 'col-sm-9'; ?>
   <?php } else { ?>
   <?php $class = 'col-sm-12'; ?>
   <?php } ?>
   <div id="content" class="<?php echo $class; ?>"><?php
//echo $my_custom_text;
//      var_dump ($download_result);
if ($download_result->num_rows > 0) {
   // output data of each row
   foreach ($download_result as $row){
       if ($row["download_id"]) {
       echo "<div class='download'>ID: " . $row["download_id"]. " - <a href='/system/download/" . $row["filename"]. "'>Download: " . $row["mask"] . "</a></div><br>";
       }
   }
} else {
   echo "0 results";
}
?><?php echo $content_bottom; ?></div>
   <?php echo $column_right; ?></div>
</div>
<?php echo $footer; ?>

~/www/catalog/controller/download/download.php

<?php
class ControllerDownloadDownload extends Controller {
public function index() {
// set title of the page
$this->document->setTitle("My Download Page");

// define children templates
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');

// set data to the variable
$data['my_custom_text'] = "This is my custom page.";
   $sql = "SELECT * FROM oc_download";
   $download_result = $this->db->query($sql);
//      var_dump ($download_result);
       $data['download_result'] = $download_result;

// call the "View" to render the output
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/download/download.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/download/download.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/download/download.tpl', $data));
}
}
}
?>

go to http://icetrousa.com/index.php?route=download/download

reference:

http://code.tutsplus.com/articles/from-beginner-to-advanced-opencart-more-about-mvc–cms-21737

http://code.tutsplus.com/tutorials/create-a-custom-page-in-opencart–cms-22054 – read comments for 2.x

Leave a Reply