The answers I received for my last question (Opencart custom admin area -> queries only showing first record of tables) were very helpful, so I decided to come back for a little more advice regarding the same project.
Whenever I redirect to a custom page/controller (i.e. /admin/index.php?route=custom/verkopen, coming from /admin/index.php?route=custom/hoofdpagina), I am asked to log in again because of an invalid token session. I've tried to google it and figure it out for myself, but the solutions I've found are either incomplete or don't work for me.
Here's my code again:
Controller main:
<?php
class Controllercustomhoofdpagina extends Controller{
public function index() {
$template="custom/hoofdpagina.tpl"; // .tpl location and file
$this->load->model('custom/hoofdpagina');
$this->template = ''.$template.'';
$this->response->setOutput($this->render());
}
}
?>
Controller subpage:
<?php
class Controllercustomverkopen extends Controller{
public function Index(){
$template="custom/verkopen.tpl"; // .tpl location and file
$this->load->model('custom/hoofdpagina');
$this->data['verkopen'] = $this->model_custom_hoofdpagina->verkopenLijst();
$this->template = ''.$template.'';
$this->response->setOutput($this->render());
}
public function verkopenTonen(){
$this->load->model('custom/hoofdpagina');
$verkopen = $this->model_custom_hoofdpagina->verkopenLijst();
return $verkopen;
}
}
?>
Model:
<?php
class Modelcustomhoofdpagina extends Model {
public function verkopenLijst() {
$query = $this->db->query("SELECT * FROM `shop_order_product`");
if($query->num_rows > 0){
$verkopen = array();
foreach($query->rows as $result){
$verkopen[] = array(
'name' => $result['name'],
'model' => $result['model'],
'quantity' => $result['quantity'],
'price' => $result['price'],
'total' => $result['total'],
'tax' => $result['tax']);
}
return $verkopen;
}
}
public function klantenLijst() {
$query = $this->db->query("SELECT * FROM `shop_customer`");
if($query->num_rows > 0){
$klanten = array();
foreach($query->rows as $result){
$klanten[] = array(
'first name' => $result['firstname'],
'last name' => $result['lastname'],
'email' => $result['email'],
'telephone' => $result['telephone'],
'date added' => $result['date_added']
);
}
return $klanten;
}
}
public function productenLijst() {
$query = $this->db->query("SELECT * FROM `shop_product_description`");
if($query->num_rows > 0){
$producten = array();
foreach($query->rows as $result){
$producten[] = array(
'name' => $result['name'],
'description' => $result['description']
);
}
return $producten;
}
}
public function productenAanpassen() {
$this->request->post['name'];
$this->request->post['text'];
$this->request->post['description'];
$this->request->post['price'];
}
}
?>
View main:
<div class="container-fluid">
<div class = "row">
<div class = "col-xs-12">
<div class = "head font-effect-neon"> Admin Area </div>
</div>
</div>
<div class="row">
<div class="col-xs-3">
<div class="button">
<a href="http://maureen.codehub.be/ew/admin/index.php?route=custom/verkopen"><button class = "buttonverkopen font-effect-neon" name = "verkopen"> Verkopen </button></a>
</div>
</div>
<div class="col-xs-3">
<div class="button">
<a href="http://maureen.codehub.be/ew/admin/index.php?route=custom/klanten"><button class = "buttonklanten font-effect-neon" name = "klanten"> Klanten </button></a>
</div>
</div>
<div class="col-xs-3">
<div class="button">
<a href="http://maureen.codehub.be/ew/admin/index.php?route=custom/producten"><button class = "buttonproducten font-effect-neon" name = "producten"> Producten </button></a>
</div>
</div>
<div class="col-xs-3">
<div class="button">
<a href="http://maureen.codehub.be/ew/admin/index.php?route=custom/aanpassen"><button class = "buttonaanpassen font-effect-neon" name = "aanpassen"> Aanpassen </button></a>
</div>
</div>
</div>
<div class = "row">
<div class = "col-xs-4">
<div class = "credits font-effect-neon"> Eindwerk </div>
</div>
<div class = "col-xs-4">
<div class = "credits font-effect-neon"> VDO Webontwikkeling 2014-2015 </div>
</div>
<div class = "col-xs-4">
<div class = "credits font-effect-neon"><span class="glyphicon glyphicon-copyright-mark"> Maureen van Eede </span></div>
</div>
View subpage:
<div class="container-fluid">
<div class = "row">
<div class = "col-xs-12">
<div class = "head font-effect-neon"> Verkopen </div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class = "php1"> <pre>
<?php
foreach($verkopen as $verkoop){
echo '<p>';
echo 'Product:'. $verkoop['name'].'<br />';
echo 'Prijs:'. $verkoop['price'];
echo '</p>';
}
?>
</pre>
</div>
</div>
</div>
Any help would greatly be appreciated.