How To Add Custom Helper / Library in App

haidarvm

Sorry I don't speak chinese,
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

1956 1 0
1个回答

phpcreeper

There are two ways:
1、Just include/require the Library/Class Files directly.
2、Use the autoloader of composer to automatically load your own Library/Class Files, just do it like so【recommended】:
(1)add the new namespace like "MyNamespace" mapping to the target Libary path by modifying composer.json:

   "autoload": {
        "psr-4": {
            "MyNamespace\\": "/path/to/your/Library"
        }   
    } 

(2)save composer.json and then execute:

composer dumpautoload

(3)now u can write any library codes as u like:

<?php
require_once "/path/to/vendor/autoload.php";
new MyNamespace\ClassX();
new MyNamespace\ClassY();
  • 暂无评论
年代过于久远,无法发表回答
×
🔝