Support » Plugin: JSON API » [Plugin: JSON API] Problem in creating External controllers

  • First of all i would like to thank dphiffer for providing such a wonderful plugin. I have downloaded it just today, so i am new with it..

    I am facing a problem while i tried to create an External controller as follow:

    I add this code at my theme’s function.php

    function add_hello_controller($controllers) {
      $controllers[] = 'hello';
    add_filter('json_api_controllers', 'add_hello_controller');
    function set_hello_controller_path() {
      return TEMPLATEPATH."/jsonAPI/hello.php"; // TEMPLATEPATH is my theme's path..
    add_filter('json_api_hello_controller_path', 'set_hello_controller_path');

    and create simple hello.php under “jsonAPI” directory at my theme as explained in description Section 5.

    it is giving warning at front end as follow:
    Warning: array_map() [function.array-map]: Argument #2 should be an array in P:\odwroot\wp301\wp-content\plugins\json-api\singletons\api.php on line 285

    Warning: array_intersect() [function.array-intersect]: Argument #1 is not an array in P:\odwroot\wp301\wp-content\plugins\json-api\singletons\api.php on line 20

    Plus an additional waring at admin side JSON API Settings:
    Warning: Invalid argument supplied for foreach() in P:\odwroot\wp301\wp-content\plugins\json-api\singletons\api.php on line 141

    and cannot see any controller there..

    however if i create controller within the plug-in directory, it is working fine.

    Kindly help..


Viewing 6 replies - 1 through 6 (of 6 total)
  • Kind Attention “dphiffer”…

    Can any body help me to find a solution for this problem????

    Having the same problem. Please provide a working example.

    I also have the same problem before. The code below works for me.

    This is the code in the theme’s functions.php

    // the external controller file
    require 'json-api.php';
    function add_hello_controller($controllers) {
      $controllers[] = 'iprofile';
      return $controllers;
    add_filter('json_api_controllers', 'add_hello_controller');
    function set_hello_controller_path() {
      return "../wp-content/themes/iProfile3/json-api.php";
    add_filter('json_api_iprofile_controller_path', 'set_hello_controller_path');

    For some reasons, I cannot use numbers in the controller names.

    Plugin Author dphiffer


    Sorry guys, there was a mistake in the documentation. The return $controllers part was a critical omission. i906’s code includes it and it sounds like it works as a result.

    I’ll look into the numbers/filters thing…

    I know that this is an old thread, but I was trying to get an external controller to work and I am having problems because it won’t find the file when you try to go to a dev url for a given function in the controller.

    I get a message of unknown controller. I traced this down to line 35 of the api.php file. I had to edit the strings to determine which one it was.

    The problem function seems to be in api.php and is named controller_path(). It seems to always look for controllers in the json_api_dir/controllers folder.

    For now I have to put my controller file into the json_api/controlders folder for it to work. Not a big deal, but I like the idea of the external controller. Should the function be passing the directory to the apply filters, or should it be passing a function name like “set_$controller_controller_path”?


    Looks like I was wrong and did get it to work, but was receiving a message that reflected an error with what was being accomplished. that Error message that got returned made me thing I didn’t get the external controller working properly.

    Talk about embarrassing.

    Thank you for making such a great plugin that is highly extensible.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: JSON API] Problem in creating External controllers’ is closed to new replies.