Extension: controller not found

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manuel7b
    Member
    • Sep 2017
    • 33

    Extension: controller not found

    Hi,

    first of all thanks for EspoCRM.

    I am writing an extension which will let me interact with Nextcloud API. You can find attached the relevant code.

    The extension correctly appears in the menu, but when I click on the menu item I get a 404 error, saying: "Nextcloud controller not found".

    Could you help me figure out what I am doing wrong?


    Thank you.
    Attached Files
  • manuel7b
    Member
    • Sep 2017
    • 33

    #2
    After more debugging with the help of some logs, I found a typo. In Nextcloud.php, under Controllers, this line:

    PHP Code:
    namespace Espo\Module\Nextcloud\Controllers; 
    
    must be:

    PHP Code:
    namespace Espo\Modules\Nextcloud\Controllers; 
    

    Comment

    • tanya
      Senior Member
      • Jun 2014
      • 4308

      #3
      Hello
      check backend controller namespace (Module{s})

      Comment

      • manuel7b
        Member
        • Sep 2017
        • 33

        #4
        Thank you, tanya.

        I have another question, don't know if I can ask here or you need me to open a different topic.

        I can now call my external API correctly and get a JSON back in the response. How can I display the result in my template? If you check the attached source code, I have an index.tpl file. I want to print the JSON in that file. Is it possible?

        Comment

        • tanya
          Senior Member
          • Jun 2014
          • 4308

          #5
          create other view for results and render results view after response

          client/src/views/list.js -> createListRecordView function (loadList) -> to view client/src/views/record/list.js

          Comment

          • manuel7b
            Member
            • Sep 2017
            • 33

            #6
            Sorry, but I don't understand. Could you share more details? I mean:

            - do I have to add another file under espocrm-nextcloud/files/client/modules/nextcloud/src/views?
            - do I have to extend client/src/views/list.js somehow?
            - it seems to me client/src/views/record/list.js operates on clientDefs. How can it operate on data coming from an external JSON?

            Thank you.

            Comment

            • tanya
              Senior Member
              • Jun 2014
              • 4308

              #7
              - it's desirable
              - no
              - pass it in 'data'

              Comment

              • manuel7b
                Member
                • Sep 2017
                • 33

                #8
                Originally posted by tanya
                - pass it in 'data'
                Do you mean something like this:
                PHP Code:
                Espo.define('nextcloud:controllers/nextcloud', 'controller', function (Dep) {
                    return Dep.extend({
                        carter: function () {
                            var result;
                            $.ajax({
                                url: 'Nextcloud/action/tweets',
                                type: 'GET',
                                dataType: 'json',
                                async: false,
                                success: function (data) {
                                    result = data;
                                }
                            });
                            return result;
                        },
                
                        getSettingsModel: function () {
                            var model = this.getConfig().clone();
                            model.defs = this.getConfig().defs;
                
                            return model;
                        },
                
                        index: function (options) {
                            var result = this.carter();
                
                            var model = this.getSettingsModel();
                            this.main('nextcloud:views/nextcloud/index', {
                                model: model,
                                data: result
                            });
                        }
                    });
                }); 
                

                This seems to be working, I can see the contents of "data" if I logged it on the JS console.

                PHP Code:
                Espo.define('nextcloud:views/nextcloud/index', 'view', function (Dep) {
                    return Dep.extend({
                
                        template: 'nextcloud:nextcloud/index',
                
                        init: function () {
                            console.log('result: ' + JSON.stringify(this.data, null, 2));
                        }
                
                    })
                }); 
                

                I still don't understand how to have it displayed in index.tpl, though.
                Last edited by manuel7b; 09-20-2017, 11:42 AM.

                Comment

                • manuel7b
                  Member
                  • Sep 2017
                  • 33

                  #9
                  I managed to print the content of data using:
                  HTML Code:
                  <div>
                      {{#each ./this}}
                      <h2>{{text}}</h2>
                      {{/each}}
                  </div>
                  Thanks for the support.

                  Comment

                  • manuel7b
                    Member
                    • Sep 2017
                    • 33

                    #10
                    Sorry if I keep asking question, I am still learning.

                    What if now I want to show the results in a list like, say, the one already existing for Opportunities?

                    Comment

                    Working...