Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将GET变量传递给Wordpress类?_Php_Wordpress_Oop - Fatal编程技术网

Php 如何将GET变量传递给Wordpress类?

Php 如何将GET变量传递给Wordpress类?,php,wordpress,oop,Php,Wordpress,Oop,大家好,我想把dr.id从一个页面发送到约会页面,我知道如何传递变量 <a href="<?php add_query_arg( 'c', $my_value_for_c, site_url( '/some_other_page/' ) )?>"> function add_custom_query_var( $vars ){ $vars[] = "c"; return $vars; } add_filter( 'query_vars', 'add_custom

大家好,我想把dr.id从一个页面发送到约会页面,我知道如何传递变量

<a href="<?php add_query_arg( 'c', $my_value_for_c, site_url( '/some_other_page/' ) )?>">

function add_custom_query_var( $vars ){
  $vars[] = "c";
  return $vars;
}
add_filter( 'query_vars', 'add_custom_query_var' );
引用这句话,

属性定义中不能有语句。改用构造函数

他们建议在构造函数中传递变量

class Appointments {
    public $c;
    public function __construct($query_var) {
        $this->$c = $query_var;
    }

    public function doSomethingWithC() {
        return $this->c;
    }
}

$my_c = get_query_var( 'c' );
$appointment = new Appointments($my_c);
echo $appointment->doSomethingWithC(); // echos the value of c

使用
$my_c=get_query_var('c')函数以获取查询参数。

实际上,我希望在类函数中包含$my_c值。。。对于例如公共函数myvar(){//这里我想要$my_c value}@SunilKashyap,我不确定是否正确,但我已经修改了我的答案。
class Appointments {
    public $c;
    public function __construct($query_var) {
        $this->$c = $query_var;
    }

    public function doSomethingWithC() {
        return $this->c;
    }
}

$my_c = get_query_var( 'c' );
$appointment = new Appointments($my_c);
echo $appointment->doSomethingWithC(); // echos the value of c