Write the common functions in espocrm please help me..................?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganesanjc
    Senior Member
    • Apr 2019
    • 116

    Write the common functions in espocrm please help me..................?

    Write the common functions in espocrm?????????
    Last edited by ganesanjc; 05-30-2019, 06:44 AM.
  • Nishan Perera
    Active Community Member
    • Jan 2019
    • 348

    #2
    what do you mean from common functions ????
    Cheers!
    Nishan.

    Comment


    • ganesanjc
      ganesanjc commented
      Editing a comment
      avoid the duplicate functions. One function need to use in multiple area with out write the function just call the function
  • manosingh
    Member
    • Apr 2019
    • 62

    #3
    He is trying to create a common function which he can able to access in any entity controller function as like helper function in code-igniter and other frameworks.

    Comment

    • telecastg
      Active Community Member
      • Jun 2018
      • 907

      #4
      Closest I can find is the "Util" class (application/Espo/Core/Utils/Util.php) which contains public static functions like:

      public static function hyphenToCamelCase(string $string) : string
      {
      return self::toCamelCase($string, '-');
      }

      that can be called from any class using the full namespace function name like:

      $name = \Espo\Core\Utils\Util::hyphenToCamelCase($name);

      However any modifications to the Util class would not be upgrade safe, so I would create a custom Util class (custom/Espo/Custom/Utils/MyUtil.php) and define your custom public static functions there like so:

      namespace Espo\Custom\Utils;
      use \Espo\Core\Exceptions\Error;
      class MyUtil
      {
      public static function myFirstFunction()
      {
      bla bla bla
      }

      }

      which could be called from another script as $anything = \Espo\Custom\Utils\MyUtil::myFirstFunction();

      I haven't tested it because I have no use for it at the moment, but hopefully it can give you an idea, if it works please share your solution so everyone can benefit :-)

      Comment

      • tothewine
        Active Community Member
        • Jan 2018
        • 373

        #5
        I am doing that but using an empty entrypoint instead of a whole new class. I've been doing that with static methods since no info is written on how to instantiate an espo-inherited class. IMHO dependency injection is a form of code obfuscation when documentation is not enough...

        Comment

        Working...