CodeIgniter Forums
How to use third party library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: How to use third party library (/showthread.php?tid=77438)



How to use third party library - Didytz - 09-02-2020

Hi,
This is maybe stupid question but I have no idea how to use third party library in my project?

I want to use http://mobiledetect.net/ library but I don't know where to put it and how to use it in my app? 
 
I tried to include it directly in my controlers but this is not correct way of doing it so please help with some instructions where to put such files?


RE: How to use third party library - InsiteFX - 09-02-2020

From the doc first you need to download Composer which will install it.

Once Composer is installed you need to run it from a terminal in the project root.

composer require mobiledetect/mobiledetectlib

Once installed just follow the rest of the instructions.


RE: How to use third party library - Didytz - 09-02-2020

(09-02-2020, 03:53 AM)InsiteFX Wrote: From the doc first you need to download Composer which will install it.

Once Composer is installed you need to run it from a terminal in the project root.

composer require mobiledetect/mobiledetectlib

Once installed just follow the rest of the instructions.

Tnx, but I forgot to metnion that I will not install it with composer, but manualy include in my project. I need to put mobileDetect.php somwhere and somehow include it in app....


RE: How to use third party library - jreklund - 09-02-2020

You do it like this: https://codeigniter.com/user_guide/concepts/autoloader.html#classmap

PHP Code:
$classmap = [
    
'MobileDetect' => APPPATH .'third_party/Mobile_Detect.php'
];

// Controller
new \MobileDetect

Depending on your needs, we kinda have it already built in:
https://codeigniter.com/user_guide/libraries/user_agent.html#isMobile