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

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • tothewine
    replied
    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...

    Leave a comment:


  • telecastg
    replied
    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 :-)

    Leave a comment:


  • manosingh
    replied
    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.

    Leave a comment:


  • ganesanjc
    commented on 's reply
    avoid the duplicate functions. One function need to use in multiple area with out write the function just call the function

  • Nishan Perera
    replied
    what do you mean from common functions ????

    Leave a comment:


  • 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.
Working...