将$ _GET传递给包含文件中的类内的函数

时间:2011-10-24 21:59:07

标签: php include get

  

可能重复:
  Can you use $_GET variables when including a file in PHP? Is it possible, even from an AJAX call?

我在包含的类中有函数但是我的配置文件页面的$ _GET没有将变量传递给类中的函数,在include文件中。

2 个答案:

答案 0 :(得分:0)

$member_id = (integer) $_GET['member_id'];
include('TheClass.php');
$obj = new TheClass();
$obj->doSomething($member_id);

如果在构造类时需要该值,则将其传递给构造函数:

$member_id = (integer) $_GET['member_id'];
include('TheClass.php');
$obj = new TheClass($member_id);
$obj->doSomething();

答案 1 :(得分:0)

在包含的页面上...

if ($_GET['var']){
    functionhere($_GET['var']);

}