【发布时间】:2016-02-21 01:55:34
【问题描述】:
我正在编写自己的 PHP 类,并且该类中有多个函数。像这样的:
class JSON_API_Hello_Controller {
public function test_cat(){
global $json_api;
$posts = $json_api->introspector->get_posts(array( 'cat' => 3));
return $this->posts_object_result_bycat($posts);
}
public function test_cat1() {
global $json_api;
$posts = $json_api->introspector->get_posts(array( 'cat' => 2));
return $this->posts_object_result_bycat($posts);
}
protected function posts_object_result_bycat($posts) {
global $wp_query;
return array(
'count' => count($posts),
'pages' => (int) $wp_query->max_num_pages,
'posts' => $posts
);
}
public function mix_cat(){
$first_cat = $this->test_cat();
$second_cat = $this->test_cat1();
print_r($second_cat);
}
}
我想在同一个类中的另一个函数中调用test_cat() 和test_cat1() 函数,例如mix_cat()。每次,它都会给出test_cat() 和test_cat1() 的结果为Null。如何调用mix_cat() 中的testcat() 和test_cat1() 函数?
【问题讨论】:
标签: php json wordpress oop json-api