Opencart自定义管理区域 - >无效的令牌会话

时间:2015-04-03 11:30:32

标签: php session customization opencart

我在上一个问题(Opencart custom admin area -> queries only showing first record of tables)收到的答案非常有帮助,所以我决定回来就同一个项目提出一些建议。

每当我重定向到自定义页面/控制器(即/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>

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

当您通过浏览器点击模块时,您已在URL中添加会话令牌作为查询字符串, 像这样'token=' . $this->session->data['token']。 如果URL中不存在会话令牌,它将永远不会转到您的自定义模块。

答案 1 :(得分:0)

我在创建自己的模块时遇到了这个问题。
解决此问题的最简单方法之一就是 在模板文件中添加$ _GET [&#39;令牌&#39;]。这样,只要管理员点击自定义模块链接,就会将一个令牌附加到管理面板的仪表板中指定的URL。为了防止无效令牌会话

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input id="filesid" type="file" name="name" multiple="multiple" />
<h2 id="show"></h2>

在config.php中

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