CodeIgniter urlencode /解码 [英] CodeIgniter urlencode/decode

查看:86
本文介绍了CodeIgniter urlencode /解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制器

function delete_payment($payment_id)
{
    $this->sale_lib->delete_payment($payment_id);
    $this->_reload();
}

查看

   <?php echo anchor("sales/delete_payment/$payment_id",'['.$this->lang->line('common_delete').']');?>

$ payment_id可能是 Gift Card:1或 Gift Card: 12345983984334

It is possible for $payment_id to be something like "Gift Card:1" or "Gift Card:12345983984334"

当它是Gift Card:1时,URL会自动解码并且删除功能会起作用,而当它是更长的字符串时,例如Gift Card:12345983984334

When it is Gift Card:1 the url is automatically decoded and the delete function works, when it is a longer string such as Gift Card:12345983984334" the url is NOT decoded.

URL是:

http://localhost/index.php/sales/delete_payment/Gift%20Card:1

http://localhost/index.php/sales/delete_payment / Gift%20Card:12345983984334

第一个有效,第二个无效

First one works, second one doesn't

推荐答案

实际上,我只是尝试在本地计算机(Windows 7上为WAMP)上复制您的情况,您是正确的,我在所有主流浏览器(FF4,IE9,Chrome)上都尝试过,但没有发现差异。

Actually, I just tried to replicate your situation on my local machine (WAMP on Windows 7) and you're right. I tried on all major browsers (FF4,IE9,Chrome) and saw no differences.

尽管这并不能真正回答您的问题,但是您始终可以使用php函数原始网址

Although this doesn't really answers your question, you can always rig a workaround like this with php function rawurldecode:

function delete_payment($payment_id)
{
    $decoded_id = rawurldecode($payment_id);
    $this->sale_lib->delete_payment($decoded_id);
    $this->_reload();
}

通过这种方式,您将以礼品卡:123456789 (我尝试过不同的工作长度和算法),为您的模型做好了准备。

In this way you'll have your 'id' in the form Gift Card:123456789 (I tried with different lenghts and alwyas worked), ready for your model.

这篇关于CodeIgniter urlencode /解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆