Welcome Guest, Not a member yet? Register   Sign In
Add library with namespaces
#1

(This post was last modified: 01-08-2015, 03:53 AM by turtuga.)

hello

I m try to add that library (http://faisalman.github.io/simple-excel-php/api/0.3/) to codeigniter but this library is build with namespaces.

Anyone can explain me how to add this library??

sorry my bad english

thanks
Reply
#2

A composer package exists: https://packagist.org/packages/faisalman...-excel-php

See this old thread https://ellislab.com/forums/viewthread/246558/ - 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: https://getcomposer.org/doc/

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.
Reply
#3

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.
Reply
#4

@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.
Reply
#5

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

Quote:http://forum.codeigniter.com/thread-473-...ml#pid3243
Reply
#6

Hello, please take a look at this tutorial: http://avenir.ro/codeigniter-tutorials/c...-composer/

I used your problem as starting point. Hope it helps.
Reply
#7

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB