External controllers in a plugin (Error)
-
Hello
I am currently developing and building a plugin based upon the JSON-API Plugin.
However I have run into a problem where the controller is not registered.At the admin screen (where you select your controllers i get this error):
Error: Cannot find controller class ‘json_api_hello_controller’
It is a very basic plugin so here you will get the sample code.
Most of it is reused from the documentation with one small exception the controller’s path.Here is the code to the files:
api-extend.php
<?php /** * Plugin Name: API Extend plugin * Plugin URI: https://localhost/ * Description: API Extender Plugin. * Version: 1.0 * Author: Lucas Dechow * Author URI: https://localhost/ * License: GPL2+ */ // Add a custom controller add_filter('json_api_controllers', 'add_my_controller'); function add_my_controller($controllers) { // Corresponds to the class JSON_API_Hello_Controller $controllers[] = 'hello'; return $controllers; } // Register the source file for JSON_API_Hello_Controller add_filter('json_api_hello_controller_path', 'hello_controller_path'); function hello_controller_path($default_path) { return plugins_url( 'hello.php' , __FILE__ ); }
hello.php
<?php /* Controller name: Hello World Controller Controller description: Basic "Hello World" method */ class JSON_API_Hello_controller { public function hello_world() { return array( "message" => "Hello, world" ); } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘External controllers in a plugin (Error)’ is closed to new replies.