2017-10-13 66 views
0

我使用wordpress REST API 2. 我为我的插件注册了以下路由。路由始终无效

register_rest_route('test-api', '/testRoom', array(

    'methods' => 'GET', 

    'callback' => 'one' 

)); 

的API:

class testRoomPlg 
{ 
    public function __construct() 
    { 

     add_action('rest_api_init', array($this, 'registerApiRoutes')); 

    } 

    public function registerApiRoutes() 
    { 
     // header("Access-Control-Allow-Origin: *"); 

     register_rest_route('test-api', '/testRoom', array(

      'methods' => 'GET', 

      'callback' => 'one' 

     )); 

    } 

    public function one() 
    { 
     var_dump('here');exit; 
    } 

} 

#kick start the plugin here 

add_action('plugins_loaded', 'loadAPI'); 

function loadAPI() 
{ 
    $setup = new testRoomPlg(); 
} 

而且我访问这样的:

http://localhost/testRoom/index.php/wp-json/test-api/testRoom

我发现,而在本地主机,需要WP之前添加的index.php -json像这样:

http://localhost/testRoom/index.php/wp-json/

但我不断收到错误: enter image description here

回答

0

我称之为类中的回调必须改变这种方式: “回调” =>阵列($此,“一”);