How to use external php library in codeigniter? |
Hey!
I'm currently creating a project where users can compare two text files (html styled or not), see the differences between those two and then request for embeding those changes in the main file (something like GitHub but without all this fuss of using commands to push changes). What i found is this library: Caxy/HtmlDiff/HtmlDiff I placed the "Caxy" folder inside "libraries" folder of my project and what i get after autoloading the library is: Autoload.php PHP Code: $autoload['libraries'] = array( View file Code: Fatal error: Class 'Caxy\HtmlDiff\AbstractDiff' not found in "path/path/path/......" on line 10 When on the other hand, i try to use it like this: PHP Code: <?php i get this PHP Code: An uncaught Exception was encountered After searching online i didn't find any solid answer on this issue.. Any ideas or suggestions? Thanks! //Life motto if (sad() == true) { sad().stop(); develop(); }
The problem is that CI can find the 'caxy/htmldiff/htmldiff' file, but cannot find any of the files it needs to load.
My suggestion is to install caxy/php-htmldiff using Composer as described on their Readme page. Then in the file /application/config.config.php use the following setting in the Composer auto-loading section PHP Code: $config['composer_autoload'] = FCPATH.'vendor/autoload.php'; In the controller that will load and use htmldiff put the following immediately after the opening PHP tag, e.g. PHP Code: <?php Do not use PHP Code: $autoload['libraries'] = array( 'caxy/htmldiff/htmldiff'); You should not use $this->load->library(). either. Instead, when you want to instantiate HtmlDiff use "new". Below I create a class property to hold the HtmlDiff object when you create one. In this example I do so in the compare method PHP Code: <?php If you want to use a HtmlDiffConfig Object include the following line right after the first "use: statement PHP Code: use Caxy\HtmlDiff\HtmlDiffConfig;
Since i don't know how to user composer yet, i think i should start learning it in order to complete this!
Thanks for you help! //Life motto if (sad() == true) { sad().stop(); develop(); } |
Welcome Guest, Not a member yet? Register Sign In |