0

我知道以前有人问过它,但我需要它来进行会员跟踪...

http://www.mysite.com/controller/method/params?affiliate=123&sub_id=456

如何获取该 URL 中列出的参数和 $_GET 参数?

4

3 回答 3

8

你总是可以得到这样的数据:

$this->input->get('your_get_variable', TRUE);

希望这有效!

于 2013-10-01T17:26:31.663 回答
3

And yet, sometimes you need access to GET variables in CodeIgniter.

One glaring example is when you use an API that sends a post-back to your site (Paypal, etc.)

The easiest way, in my opinion, is to parse a server variable with the GET data you need since $_GET has been wiped (in my example, REQUEST_URI has my GET data.):

parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);

This allows the functionality exactly where you need it without requiring a global change to framework settings.

Here is a usage example.

class Pgate extends Controller {
   function postback() {
      parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
      $receipt = $this->input->xss_clean($_GET['receipt']);
   }
}
于 2010-08-04T18:13:30.970 回答
0

如果你真的想在 codeigniter 中使用查询字符串,你可以使用http://site.com?c=controller&m=method&param1=x&param2=y

这不是 codeigniter 中的约定,通常人们使用斜杠来分隔参数。

于 2010-08-04T14:03:54.993 回答