Php 如何将GET变量传递给Wordpress类?
大家好,我想把dr.id从一个页面发送到约会页面,我知道如何传递变量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
<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