How do I include the OOP “defiant randomdotorg” library in codeigniter?

前端 未结 1 686
走了就别回头了
走了就别回头了 2020-12-04 01:41

The class is here (with instructions).

I have it added to application/libraries/randomorg

When I add $this->load->library(\'RandomOr

相关标签:
1条回答
  • 2020-12-04 02:06

    I know I've answered this question before I just can't find where and don't know what to search. So here it is: Codeigniter can only load single php file libraries (excluding drivers which is a different thing entirely). To load this kindof library (namespaced) you have to use something like: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md (class example).

    Let's call it Autoloader_psr4 and save it in libraries (modify the class declaration to match this name verbatim (e.g. Autoloader_psr4). Remove the namespace declaration in the class so it looks like: https://pastebin.com/NU8Rbp7Y

    Let's also move all the files in src/randomorg/ to just be in a folder in third_party called RandomOrg e.g. application/third_party/RandomOrg. Your folder should look like the contents here: https://github.com/defiant/randomorg/tree/master/src/randomorg

    Usage:

    $this->load->library('autoloader_psr4');
    $this->autoloader_psr4->register();
    $this->autoloader_psr4->addNamespace('RandomOrg', APPPATH . 'third_party/RandomOrg');
    $random = new \RandomOrg\Client(); // or whatever...
    
    0 讨论(0)
提交回复
热议问题