CodeIgniter Forums
Add library with namespaces - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: Libraries & Helpers (
+--- Thread: Add library with namespaces (/showthread.php?tid=681)

Add library with namespaces - turtuga - 01-05-2015


I m try to add that library ( to codeigniter but this library is build with namespaces.

Anyone can explain me how to add this library??

sorry my bad english


RE: Add library with namespaces - ivantcholakov - 01-05-2015

A composer package exists:

See this old thread - This is an example about how to activate Composer in CodeIgniter (a config setting is to be touched) and how to install a package.

Have a look at Composer's documentation too:

After installing the package faisalman/simple-excel-php try its sample usage code (that is on the github page) within a controller to test whether it works.

RE: Add library with namespaces - mwhitney - 01-05-2015

There are basically two options to approaching this:

1) Just use it as instructed by the existing documentation.
2) Build a wrapper/adapter to make the library available as if it were a CI library.

#1 is usually the easiest way to handle it, but it sometimes causes issues for some people to switch code styles in the middle of a controller (or wherever you happen to be using it).

#2 usually involves little more than creating a CI library which loads the required files for the non-CI library (or you can use Composer to load the files) and initializes the library as needed in the constructor.

Of course, the more extensive the use of the library, the more likely it is that you will have to write additional code to make the library interact with your code in this manner. In the end, that code is only of significant value if you intend to be able to swap out the underlying library in the future and/or you know that switching coding styles to use this library will be an issue.

RE: Add library with namespaces - ivantcholakov - 01-05-2015

@mwhitney I like #2. It is a little more work, but hiding the API of an external component behind an ordinary CI library later makes replacing the component possible.

RE: Add library with namespaces - no1youknowz - 01-05-2015

I agree with #2 also.  I mentioned it in another post.


RE: Add library with namespaces - Avenirer - 01-06-2015

Hello, please take a look at this tutorial:

I used your problem as starting point. Hope it helps.

RE: Add library with namespaces - XMadMax - 01-21-2015

The CI 3.0 dev now comes with composer autoloader. You can also use in your 2.x (copy & paste from /core/Codeigniter.php to same in older version)

To use any library in composer, simply use the namespace when calling: example: \MyComposerLib