Customer Portal

Get Involved. Join the Conversation.

Topic

    Pablo Rossetti
    How to create a custom ajax controller?Answered
    Topic posted February 4, 2016 by Pablo RossettiRed Ribbon: 250+ Points 
    991 Views, 10 Comments
    Title:
    How to create a custom ajax controller?
    Content:

    Hello everybody. Today my problem is a simple one. I don't know how to create a custom controller. What I want to do is something like this:

    https://cloudcustomerconnect.oracle.com/posts/c570c3f233

    https://cloudcustomerconnect.oracle.com/posts/3b66a69151

    In both cases they use their own ajax controller for this function: RightNow.Ajax.makeRequest(myCustomAjaxControllerHere, param2, param3) and that's exactly what I want to do but I couldn't find any thread or document explaining how to create that file and how to obtain its rute/directory.



    Hope you can help me!

    Regards,

    Pablo

    Best Comment

    Rajan Davis

    Let's back up for a second. 

    Which Customer Portal framework version are you using?

    Also, do not worry about the "cc" and "ci" folders, these have nothing to do with WHERE the files are on the server whereas the represent a particular resource for various widgets. The server looks at if you are in the development mode and the URL's and knows that the files should be in some controller folder.

    So for now, completely ignore this part of the equation and follow the instructions below.

    If you are on version 2 (which I am using, I am putting this information here for posterity's sake because I had to learn this the hard way), you will need to go to the dav folder, then the euf folder, then to the  development folder, and then the controllers folder and paste the file in there.

    It should be accessible from the URL I gave you ( https://<your-interface>.custhelp.com/cc/ajax_controller_example/test ).

    If you are on 3+, it's a different file location and, apparently, you need to modify the file a bit differently to have the custom controllers namespace. I have updated the controller file here; I tested on the portal framework 3 in development, so it should work if you put the file in the correct location.

    Side note: in this file above, I have included the ConnectPHP API initialization so that you can use it. It is a freakishly robust API that allows you to do anything you really want. It is purely optional, but I am definitely using it in these controllers.

    You have to place the file in /dav/cp/customer/development/controllers folder (shown below).

    Once the file is in the correct place, you can access it from the URL that I gave you previously (https://<your-interface>.custhelp.com/cc/ajax_controller_example/test)

     

    I have tested this on both frameworks and it should work. I get the following result:

    Let me know if you need any further assistance.

    Also, if you want to pretty print your JSON response, I am using a chrome extension called JSON View to make the response look nicer (i.e. it's nested and indented).

    Comment

     

    • Kesava Kumar

      Hi,

      Follow this path and there you have to create your own custom controller.

      cp/Customer/development/controllers

      And then RightNow.Ajax.makeRequest(myCustomAjaxControllerHere, param2, param3)

      here you have to give path like this

      RightNow.Ajax.makeRequest(cc/ControllerName/ControllerFunctionName, param2, param3)

      Thanks

      kesava

    • Rajan Davis

      Here is a comment that I posted with some controller code; you can will need to put this in the specified folder above. Let me know if you need any help.

    • Pablo Rossetti

      Thank you for your comments. My biggest doubt now is that I don't now in which folder and through which software (Cyberduck or RightNow) should I upload my ajax_controller.php file.
      Regards,
      Pablo.

    • Pablo Rossetti
      Kesava Kumar said:

      Hi,

      Follow this path and there you have to create your own custom controller.

      cp/Customer/development/controllers

      And then RightNow.Ajax.makeRequest(myCustomAjaxControllerHere, param2, param3)

      here you have to give path like this

      RightNow.Ajax.makeRequest(cc/ControllerName/ControllerFunctionName, param2, param3)

      Thanks

      kesava

      View original

      Do I have to create a new folder inside controllers default folder? I ask this because you are using cc/ for the custom file directory. Is cc a folder I should create?

    • Rajan Davis

      You do not need to create a new folder. All you have to do is place the file into the folder.

      You should be able to access the file (while in development mode) by using the following URL scheme:

      https://<your-interface>.custhelp.com/cc/ControllerName/ControllerFunction

      Using the file I provided you, would use the following scheme:

      https:/<your-interface>.custhelp.com/cc/ajax_controller_example/test

      You should get the following response:

      ["an","array","of","words"]

      I will note, you can only access this controller publicly when it has been moved into production. If it resides in your development area, it can only be accessible from pages in your development area.

    • Pablo Rossetti

      Thank you again. The problem is that I can't find any folder with the name "cc/". I'm working in a test instance, in development mode. My url is https://<your-interface>--tst1.custhelp.com and I work with Cyberduck. All the files I edit are inside dav/cp/customer/... and there's no folder with the name cc. I have only managed to found the folder controllers/ where I have a file named AjaxCustom.php and realized that this route in the browser is translated to this https://<your-interface>--tst1.custhelp.com/ci/AjaxCustom/functionName and I wonder WHY? Where is that ci/ folder? Where is cc folder? It's so confusing.

      Hope you can help me!
      Regards

    • Rajan Davis

      Let's back up for a second. 

      Which Customer Portal framework version are you using?

      Also, do not worry about the "cc" and "ci" folders, these have nothing to do with WHERE the files are on the server whereas the represent a particular resource for various widgets. The server looks at if you are in the development mode and the URL's and knows that the files should be in some controller folder.

      So for now, completely ignore this part of the equation and follow the instructions below.

      If you are on version 2 (which I am using, I am putting this information here for posterity's sake because I had to learn this the hard way), you will need to go to the dav folder, then the euf folder, then to the  development folder, and then the controllers folder and paste the file in there.

      It should be accessible from the URL I gave you ( https://<your-interface>.custhelp.com/cc/ajax_controller_example/test ).

      If you are on 3+, it's a different file location and, apparently, you need to modify the file a bit differently to have the custom controllers namespace. I have updated the controller file here; I tested on the portal framework 3 in development, so it should work if you put the file in the correct location.

      Side note: in this file above, I have included the ConnectPHP API initialization so that you can use it. It is a freakishly robust API that allows you to do anything you really want. It is purely optional, but I am definitely using it in these controllers.

      You have to place the file in /dav/cp/customer/development/controllers folder (shown below).

      Once the file is in the correct place, you can access it from the URL that I gave you previously (https://<your-interface>.custhelp.com/cc/ajax_controller_example/test)

       

      I have tested this on both frameworks and it should work. I get the following result:

      Let me know if you need any further assistance.

      Also, if you want to pretty print your JSON response, I am using a chrome extension called JSON View to make the response look nicer (i.e. it's nested and indented).

    • Pablo Rossetti

      I'm using version 3.2 I think. The problem is that Cyberduck is not allowing me to create files inside the controllers folder, it only lets me modify the AjaxCustom.php file that is in it. I now think it should be related with my user profile permissions given the fact that you do can do it.
      Besides that, I think that in my case, it doesn't recognize in browser that directory with cc/ but yes with ci/, don't know why.
      Anyway your answer is very complete and now I know for sure that the correct folder is /controllers, so thank you very much for it. I've managed to "solve" my issue with another resource for now...
      Regards,
      Pablo.

    • Rajan Davis

      Which version of Cyberduck are you using? 



      You have to use 4.4.3, I posted something about this on one of the main topics.



      Glad I could help, had a *** of time learning this stuff myself.

    • Pablo Rossetti

      Rajan Davis said:


      Which version of Cyberduck are you using? 



      You have to use 4.4.3, I posted something about this on one of the main topics.



      Glad I could help, had a *** of time learning this stuff myself.


      View original


      I'm using the last version (4.7.3) for WINDOWS. Should I download the version 4.4.3 (for Windows)?