2015-04-03 77 views
0

我收到的关于我最后一个问题(Opencart custom admin area -> queries only showing first record of tables)的答案非常有帮助,因此我决定回来多一点关于同一项目的建议。Opencart自定义管理区域 - >无效令牌会话

无论何时我重定向到自定义页面/控制器(即/admin/index.php?route=custom/verkopen,来自/admin/index.php?route=custom/hoofdpagina),我都会被要求登录再次因为无效的令牌会话。我试图谷歌并找出自己的,但我发现的解决方案不完整或不适合我。

这里是我的代码再次:​​

控制器主:

<?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()); 
} 

} 

?> 

控制器子页面:

<?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; 
    } 

} 




?> 

型号:

<?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']; 



} 

} 

?> 

视图主:

<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> 

查看子页面:

<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> 

任何帮助将大大赞赏。

+0

你缺少'令牌= '在链接 – Justinas 2015-04-03 11:36:27

+0

添加令牌到你的链接,你可以在这里找到http://stackoverflow.com更多信息/ a/16568404/2282628 – 2015-04-03 12:09:15

+0

谢谢,那工作:) – ssm 2015-04-03 13:29:53

回答

1

当你通过浏览器打开模块时,你已经在url中添加了会话令牌作为查询字符串, 像这样'token=' . $this->session->data['token']。 如果会话令牌不在url中,它永远不会去你的自定义模块。

0

我在创建自己的模块时遇到了这个问题。
解决此问题的一种最简单的捷径是 在模板文件中添加$ _GET ['token']。因此,无论管理员何时单击自定义模块链接,标记都会附加到管理面板的仪表板中给出的URL。为了防止无效令牌会话

<li><a href="<?php echo DOMAIN_API_SYNC; ?>&token=<?php echo $_GET['token']; ?>" <i class="fa fa-key"></i> <span><?php echo "API ACCESS"; ?></span></a></li> 

在config.php

// URL 
define('DOMAIN_API_SYNC', 'Domain_Name.org/admin/index.php?route=yourdirectory/your_file');