webman icon indicating copy to clipboard operation
webman copied to clipboard

How To Add Custom Helper / Library in App

Open haidarvm opened this issue 5 years ago • 3 comments

Just Like Codeigniter or any other php framework, they have Helper / Library for custom function & library

function allowTags($text) {
    $tags = '<strong><h1><h2><h3><h4><br><hr><b><ol><ul><u><span><li><a><img><iframe>';
    return strip_tags(html_entity_decode(trim($text)), $tags);
}

for example I create multiple Controller and want to call the function allowTags() in any controller

haidarvm avatar Sep 10 '20 22:09 haidarvm

@walkor , @passwalls , please I really need this feature. I would definitely donate this project soon

haidarvm avatar Sep 12 '20 07:09 haidarvm

Webman currently does not strictly specify the location of custom function & library.

You can put your helper functions into for example app/functions.php. And add line "./app/functions.php" in composer.json like this.

"autoload": {
    "files": [
      "./support/helpers.php",
      "./app/functions.php"
    ]
  },

Run command composer dump-autoload then the ./app/functions.php will be loaded automatically .

Make your class file conform to psr4 rules, and it will be loaded automatically. For example app/common/User.php.

namespace app\common;
class User
{
}

It will be loaded automatically when it used.

walkor avatar Sep 12 '20 08:09 walkor

Oh, Ok i got it. For temporary I will using composer psr4

haidarvm avatar Sep 12 '20 09:09 haidarvm