title: How and where to instantiate a custom class that extends the WP_REST_Controller
body: <p>I have a plugin that I created and I want to use the WP rest api <a href="http://v2.wp-api.org/extending/adding/" rel="nofollow">controller pattern</a> in order to extend the api.</p>
  
  <pre><code>&lt;?php
  /**
  * Plugin Name: myplugin
  * Plugin URI: h...
  * Description: A simple plugin ...
  * Version: 0.1
  * Author: Kamran ...
  * Author ....
  * License: GPL2
  
  function myplugin_register_endpoints(){
  
     require_once 'server/controllers/my_ctrl.php';
     $items=new items();
     $items-&gt;register_routes();
  
  }
  
  add_action('rest_api_init','myplugin_register_endpoints');
  .
  .
  </code></pre>
  
  <p>I created a class a folder called server/controllers and inside it my_ctrl.php file with a class that extends WP_REST_Controller that looks like this</p>
  
  <p>// server/controllers/my_ctrl.php</p>
  
  <pre><code>class items extends WP_REST_Controller {
  
      /**
      * Register the routes for the objects of the controller.
      */
       public function register_routes() {
         .....
       }
  
  }
  </code></pre>
  
  <p>However I am receiving the following error in sublime xdebuge call stack:</p>
  
  <p>[Fatal error] Class 'myplugin\WP_REST_Controller' not found</p>
  
  <p>I am not sure how to solve this issue, where to put the files for my custom controller, where to create the instance of the custom class etc?</p>