Overriding entity controller

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The50
    Member
    • Nov 2017
    • 39

    Overriding entity controller

    Hello,

    How could I make an override for entity controller? I made an override for "Account" entity and I want to make a custom AJAX call from that view.

    I have this request:

    this.ajaxPostRequest(this.scope + '/action/myFunction', {
    UserCode: this.model.attributes.sicCode }).then(function (attributes)
    {
    console.log(attributes);
    }.bind(this));

    Now how could I override the "Account" controller? I created the override file here: custom/Espo/Custom/Controllers/Account.php
    Function "myFunction" is of course inside it, but it still doesn't see it and says that there is no myFunction in "Account" controller.

    The controller file is here:

    PHP Code:
    <?php
    namespace Espo\Core\Controllers;
    class Account extends Base
    {
        public function myFunction()
        {
            die(true);
        }
    }
    What am I doing wrong?
    Last edited by The50; 12-19-2017, 03:45 PM.
  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #2
    http://forum.espocrm.com/forum/devel...mplate-in-html
    http://forum.espocrm.com/forum/developer-help/23755-how-to-call-a-custom-method-of-controller

    Comment

    • The50
      Member
      • Nov 2017
      • 39

      #3
      Nice, thank you. The problem was my controller namespace

      PHP Code:
      namespace Espo\Custom\Controllers;
      use Espo\Core\Controllers\Record as RecordUsage;  
      
      class Account extends RecordUsage
      {    
      public function postActionGetHashedLogin($request, $params)    
      {        
      return json_encode(crypt($params['userCode'], 'test'));    
      }
      } 
      

      Comment

      • tanya
        Senior Member
        • Jun 2014
        • 4308

        #4
        I think is better when class Account extends \Espo\Modules\Crm\Services\Account, because you lose the default functionality

        Comment

        • The50
          Member
          • Nov 2017
          • 39

          #5
          Originally posted by tanya
          I think is better when class Account extends \Espo\Modules\Crm\Services\Account, because you lose the default functionality
          I just tried it, but this way I get bad server response error when I get to the main "Account" page where the list of all the accounts is present.

          Comment

          • tanya
            Senior Member
            • Jun 2014
            • 4308

            #6
            sorry, not Service, but Controller - \Espo\Modules\Crm\Controllers\Account

            Comment

            Working...