编码/解码不总是工作-Codeigniter


Encode/Decode not always working - Codeigniter

我有一个从数据库中删除的删除按钮。我按下页面上的删除按钮,在我按下几次之前,它不会起任何作用。有时,它只是一次尝试就从数据库中删除了值,有时,我必须多次按下删除按钮才能删除。有什么办法克服这个吗?

我的视图文件:

//other code above
<?php $encrypted = $this->encrypt->encode($data->pid); ?>
<a href="<?php echo base_url() . "profile/delete_entry/" .  $encrypted; ?>">Delete</a>
//other code below

我的控制器:

$this->load->model('model_entry');
    $pid = $this->uri->segment(3);
    $result = $this->model_entry->entry_delete($pid);
    //redirect to entries index.php

我的型号

public function entry_delete($pid) {
    $pid = $this->encrypt->decode($pid); //to decode
    $uid=$this->session->userdata('uid');
    $whereConditions = array('pid' => $pid, 'uid' => $uid);
    $this->db->where($whereConditions);
    $this->db->delete('dayone_entries');
}

不确定是否可以在URL中放置加密数据。Codeigniter将不允许您使用具有特殊字符(如"=")的URL。正如我所知,如果您执行类似$encrypted = $this->encrypt->encode($data->pid);的操作,它将返回一个末尾带有双"="的字符串。

以下是关于CodeIgniter中加密的解释。Codeigniter 上的加密字符串