2017-10-13 11 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 like this:

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

しかし、私はエラーを取得しておくよ: enter image description here

答えて

0

私はクラス内でコールバックを呼び出す方法はこれに変更する必要があります。 「コールバック」=>配列($この、「1」);

関連する問題